0

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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
userXktape
  • 227
  • 3
  • 5
  • 15
  • its not really a duplicate – userXktape Jul 13 '16 at 08:14
  • The real duplicate is the canonical *[Compilation error: stray ‘\302’ in program, etc.](https://stackoverflow.com/questions/19198332)*. – Peter Mortensen Mar 06 '21 at 15:04
  • A much more direct analysis is 342 210 222 (octal) → 0xE2 0x88 0x92 (hexadecimal) → UTF-8 sequence for Unicode code point U+2212 ([MINUS SIGN](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=8704&number=128)). – Peter Mortensen Mar 06 '21 at 20:05

1 Answers1

2

There is the unprintable on

if (ret == −1) {

Replace it with -

GMichael
  • 2,726
  • 1
  • 20
  • 30
  • Thanks bro.It works :) – userXktape Jul 13 '16 at 05:32
  • To be more precise, it is Unicode code point U+2212 ([MINUS SIGN](https://www.utf8-chartable.de/unicode-utf8-table.pl?start=8704&number=128)). In most text editors it can be searched/replaced by a regular expression search for `\x{2212}`. – Peter Mortensen Mar 06 '21 at 20:04