**Record the common problems you encounter in file operations**
The case of garbled output
When using C language, we generally use fopen
functions to open files, as follows
#include<stdio.h>
int main()
{
FILE *fp;
char a[10];
fp=fopen("temp.txt","r");
fscanf(fp,"%s",a);
printf("%s\n",a);
return 0;
}
If the output is all garbled characters
, open the corresponding temp.txt text file, select the file in the upper left corner to save it as, change the encoding from UTF-8 to ANSI at the bottom and save it, and then output the text normally (be careful not to memory space exceeded).
Related operations of fopen function reading and writing
fopen
Some operation applications of functions
fopen("***.txt","w");
When using fopen
the function to open a file, if you want to continue writing data on the original basis, use a
will w
clear the original data in the document first, and a is to add data at the end of the document, and the pointer points to the end of the document.
It can also be used r+
, r+
and w+
both are read-write modes, the difference is that w+
the file will be cleared first.