On Thu, 7 Aug 2008, Gabor Kovesdan wrote:

Hello,

I'm wondering why fgetc() returns 0xff if called with /dev/null:

#include <stdio.h>
#include <stdlib.h>

int
main(void)
{
      int      c;
      FILE    *f;

      f = fopen("/dev/null", "r");

      if (c != EOF)
              printf("%c\n", fgetc(f));
}

Hmmm, are you *sure* your code should not be written as follows:

#include <stdio.h>
#include <stdlib.h>

int
main(int argc, char **argv)
{
        FILE *f;
        int c;

        f = fopen("/dev/null", "r");
        if (f != NULL) {
                c = fgetc(f);
                if (c != EOF)
                        printf("%c\n", c);
                else
                        printf("EOF encountered\n");
        }
        return (0);
}

--
DE
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to