c - 为什么 while 写在这里没有 body ?

标签 c syntax while-loop fgetc

为什么这段代码写的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/

相关文章:

php - 查询中的 ORDER BY 不适用于循环

java - 循环空指针异常

c - 使用 pthread_barrier_wait 是否确保变量可见性?

c - C中的二叉树崩溃

c++ - C++结构语法 “a : b”是什么意思

android.database.sqlite.SQLiteException : near "": syntax error

c - 使用 strtok 在 C 中解析字符串

c - gtk_window_set_ressized 将窗口设置为最小

git - git diff hunk header 中的摘录来自哪里?

PHP:让您自己的函数使用 while 循环