c++clinuxsystems-programming

Error with stray ‘\342’ stray ‘\210’ stray ‘\222’ in C program in Linux system call


I am trying to do an example on a poll system call from Robert Love's book Linux system programming, 2nd edition (page 60-61). I copy pasted the example code in Code::Blocks on Ubuntu 14.04 (Trusty Tahr) and tried compiling it, but I get errors related to stray '/342' '/210' and '/222' in my code.

Following is the code: It throws error on line 18 where if(ret == -1) is checked

#include <stdio.h>
#include <unistd.h>
#include <poll.h>

#define TIMEOUT 5

/* Poll timeout, in seconds */
int main (void)
{
  struct pollfd fds[2];
  int ret;

  /* Watch standard input for input */
  fds[0].fd = STDIN_FILENO;
  fds[0].events = POLLIN;

  /* Watch standard output for ability to write (almost always true) */
  fds[1].fd = STDOUT_FILENO;
  fds[1].events = POLLOUT;

  /* All set, block! */
  ret = poll(fds, 2 , TIMEOUT*1000);

  if (ret == −1) {
    perror("poll");
    return 1;
  }

  if (!ret) {
    printf ("%d seconds elapsed.\n", TIMEOUT);
    return 0;
  }

  if (fds[0].revents & POLLIN)
    printf ("stdin is readable\n");

  if (fds[1].revents & POLLOUT)
    printf ("stdout is writable\n");

  return 0;
 }

The errors are:

/home/eelab/sysprog/pollex/main.c|18| error: stray ‘\342’ in program|
/home/eelab/sysprog/pollex/main.c|18| error: stray ‘\210’ in program|
/home/eelab/sysprog/pollex/main.c|18| error: stray ‘\222’ in program|

Now, I've gone through similar questions on Stack Overflow and they mention the possible problem being with conversion of ASCII characters like quotes " ". However, I have rewritten all quotes in the IDE again. But it still throws the same error on the line where if(ret == -1 ) is checked.


Solution

  • There is the unprintable on

    if (ret == −1) {
    

    Replace it with -