【问题标题】:Not able to print file content on screen无法在屏幕上打印文件内容
【发布时间】:2019-11-28 21:00:25
【问题描述】:

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

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

感谢您的宝贵时间。

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;
}

【问题讨论】:

    标签: c file printing console


    【解决方案1】:

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

    【讨论】:

    • 谢谢!由于我在这里没有足够的声誉,所以我无法支持您的评论,但它非常有帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-03-07
    • 2013-05-08
    • 1970-01-01
    • 1970-01-01
    • 2010-11-21
    • 1970-01-01
    • 2015-06-06
    相关资源
    最近更新 更多