Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If the first character in file "foo" isn't a null, a newline or a carriage return, your program will enter an infinite loop at line 9 :)


Yes. EOF is 0, so it will grab all the characters as digits, for the length of the file up until an EOF.


The value of EOF is platform-specific, but is commonly -1. I'm fairly sure it's never 0.

But I was referring more to the fact that c is set exactly once in line 4 (`int c = getc(fd)`), outside of the nested loops, and never touched again. So if it's not initially a NULL, newline or CR, it never will be, and the inner loop will never exit.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: