为什么我写给文件的文字会一直更改为汉字?

问题描述 投票:0回答:1

您可能想要这样的东西:
#include <stdio.h>
#include <stdlib.h>

int main()
{
  FILE* fptr;

  // Create the file and write to it
  fptr = fopen("C:\\Users\\USER\\Downloads\\text.txt", "w");
  fprintf(fptr, "Hello World\n");
  fclose(fptr);  // >>>>> don't forget to close the file <<<<<

  // open the file we created before, and read one line from it
  fptr = fopen("C:\\Users\\USER\\Downloads\\text.txt","r");
  char input[100];
  fgets(input, 100, fptr);
  fclose(fptr);

  printf("%s", input);
}
c file-handling
1个回答
0
投票
没有任何错误检查什么,我将其作为练习给您。 提示:

fopen

可以返回
NULL
,这表明由于某种原因无法打开文件(最常见的原因之一是该文件不存在)。


最新问题
© www.soinside.com 2019 - 2024. All rights reserved.