3 ms·
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 :)
by dghf 10y ago
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 :)
- fao_ 10y agoYes. EOF is 0, so it will grab all the characters as digits, for the length of the file up until an EOF.
- dghf 10y agoThe 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.