Yesterday introduced the reading of C language files, and then introduced the writing of C language files.
The reading of C language is the three functions of fgetc(), fgets(), and fread().
Then the writing must be the three functions fputc(), fputs(), and fwrite(). Let's try that next.
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[])
{
//第一步打开文件
FILE* file = fopen("test.txt", "w");
//进行判定
if (file == NULL)
{
printf("打开文件失败!!!");
return 0;
}
fputc('A', file);
fputs("我",file);
fwrite("你快回来",2,8,file);
//第三步关闭文件
fclose(file);
return 0;
}