为什么这段代码写的while循环没有body?它有什么作用? 索引和长度都是整数,我正在从一个 txt 文件中读取。
// ignore alphabetical strings too long to be words
if (index > LENGTH)
{
// consume remainder of alphabetical string
while ((c = fgetc(fp)) != EOF && isalpha(c));
// prepare for new word
index = 0;
}
最佳答案
一旦它解析了长度为 LENGTH 的字符串,它应该忽略所有后续字符。因此,在 while 循环体中:
c = fgetc(fp)) != EOF //get c from file pointer and check if it is not EOF
isalpha(c) //and also it is an alphabet because alphabets can only make a word
如果两个条件都为真,继续解析并忽略。当您遇到字母表以外的字符或只是 EOF 时,请重置索引并转到下一行。
关于c - 为什么 while 写在这里没有 body ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38857976/