在c编程中逐行读取文本文件

时间:2014-11-25 01:25:03

标签: c

我如何逐行读取文本文件,因此每行将在代码的下一部分输入,然后这部分将比较该文件中的第一行,如果它不正确,那么它将尝试下一个,依此类推,直到找到正确的单词?

请帮助你?

>  FILE *userfp;    // usernames file pointer
      int countusr = 0;  // conter for file lines
      char  word[BUFSIZE];
      char *cpyword;
      userfp = fopen(UsrsFile,"r");

      // check if file exits

      if (userfp == NULL)
       {
        errorMessage("usernames File doesn't exit!");
       }  
 int x = 0; int s=0;
        while (!feof(userfp)) {
                fgets(word, BUFSIZE, userfp);
                if (word[BUFSIZE] == '\n')
                        continue;
                for (s = 0; s < strlen(word); s++)
                        if (word[s] == '\n')
                                //word[s] = ',';
               //cpyword[x] = malloc(BUFSIZE);
                //strcpy(cpyword[x], word);
                //x++;
                printf("%s",word);

        }

0 个答案:

没有答案