c - 如何重置 while 循环?

标签 c while-loop

这是我正在处理的一些代码的摘录。只是想知道我将如何重置嵌套循环?当第一个循环再次运行时,它保留在文件末尾。

while(fscanf(fp2,"%s", wordcheck)!=EOF)//Reads word from text file into array//
    {

        for (i=0; wordcheck[i]; i++)
        {
            wordcheck[i] = tolower(wordcheck[i]);//makes all characters lower case//
        }

        printf("%s", wordcheck);

        while(fscanf(fp1,"%s", worddict))
        {   
            if(strcmp(wordcheck, worddict)==0)//compare strings//
            {
            printf("This word: %s is in the dictionary\n", wordcheck);
            dictcount++;
            break;
            }

            else
            {
            dictcount++;
            }

            if(worddict == NULL)
            {
            printf("Your word: %s is not in the dictionary\n", wordcheck);
            }
        }
    }

最佳答案

使用fseek :

fseek(fp2, 0, SEEK_SET);

.. 或者更简单地说,rewind :

rewind(fp2);

关于c - 如何重置 while 循环?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8576785/

相关文章:

C chars 和 char* 指针的索引

c++ - 优化 C++ 中的大整数减法

python - python中的平方根算法

c - 如何检查输入字符串是否由整数组成

PHP While 循环从多个 'Joined' 表中分离唯一类别

javascript - 每次循环分配新值时 DRY

c - 为什么使用 atoi 命令行参数出现段错误

c - GCC Win32 API 与 ComCtl32 的链接问题

无法从命令行编译c文件

c - 多线程程序额外运行while循环次数