无法在屏幕上打印文件内容

时间:2019-11-28 21:00:25

标签: c file printing console

我需要将一个文件的内容复制到另一个文件,然后在屏幕上打印另一个文件的内容。

程序创建文件并复制内容没有问题,但是它不会在屏幕上打印任何内容。

感谢您的时间。

void organizeContent(FILE *file) {

  FILE *file_student = fopen("student.txt", "w+");

  int ch;
  while((ch = fgetc(file)) != EOF)
    fputc(ch, file_student);
  fflush(file_student);

  int ch2;
  while((ch2 = fgetc(file_student)) != EOF) {
    fputc(ch2, stdout);

  return;
}

1 个答案:

答案 0 :(得分:1)

在第一个while循环之后,file_student流将位于文件的末尾。再次fclosefopen文件,或者rewind再读回文件。