This while
is written with no body, because the action is carried out in the condition
part of the while
loop.
If you see the condition of the loop it is:
((c = fgetc(fp)) != EOF && isalpha(c))
When first condition - i.e. (c = fgetc(fp)) != EOF
- is evaluated, c = fgetc(fp)
gets executed, which reads one byte from your file. This byte is first checked if it is EOF
, which signifies end of file, and if not EOF then it is checked if it is a non-alphabet character.
This action of reading one byte from the file continues either untill either a non-alphabet character is read, or the end of file is reached.
So, what this snippet of code basically does is, whenever index
becomes more than LENGTH
, it first reads remaining alphabets
- without doing anything -, untill a non-alpbabet is read or the end of file is reached. And then it setsindex
to 0
.
That while could be written differently too, so that it would not have an empty body. However, what you have seen is a common idiom
in C
.