分隔文本文件

时间:2017-02-16 19:27:25

标签: c

我正在尝试阅读名为myfile.txt的文本文件,并将第2,4,6行复制到名为even.txt的文本文件中,并将第1,3,5行复制到odd.txt 。我是编程新手,这可能是非常错误的。任何帮助将不胜感激。

int main()
{
  FILE *fp;
  FILE *feven;
  FILE *fodd;
  int lines = 0;

  fp = fopen("myfile.txt","r");
  if (fp ==NULL) {
    printf("Cannot open file.\n");
    exit(1);
  }

  feven = fopen("even.txt","w");
  if (feven ==NULL) {
    printf("Cannot open file.\n");
    exit(1);
  }

  fodd = fopen("odd.txt","w");
  if (fodd ==NULL) {
    printf("Cannot open file.\n");
    exit(1);
  }

  while (fscanf(fp, "%s") != EOF) {
    lines++;
    if (lines%2=0)
    {fprintf(feven,"%s \n");}
    else
    {fprintf(fodd,"%s \n",);}
  }
}//end program

1 个答案:

答案 0 :(得分:1)

您没有空间存储这些行,我建议A PHP Error was encountered Severity: Warning Message: unlink(assets/admin/uploads/photostory_img/): Permission denied Filename: nautics/Pstory.php Line Number: 293 Backtrace: File: C:\wamp64\www\JSNCI\application\controllers\nautics\Pstory.php Line: 293 Function: unlink File: C:\wamp64\www\JSNCI\index.php Line: 315 Function: require_once (注意您的代码可以使用指向fgets的指针数组进行简化):

FILE