按照字符进行读写
- 写文件 fgetc
- 读文件 fputc
- 文件结尾 EOF END
代码示例:
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void test01()
{
FILE*f_write = fopen("./test.txt","w");
if (f_write == NULL)
{
return;
}
char buf[] = "hello C++!";
for (int i = 0; i < strlen(buf); i++)
{
fputc(buf[i],f_write);
}
fclose(f_write);
FILE*f_read = fopen("./test.txt", "r");
if (f_read == NULL)
{
return;
}
char ch;
while ( (ch = fgetc(f_read)) != EOF)
{
printf("%c",ch);
}
fclose(f_read);
}
int main()
{
test01();
return EXIT_SUCCESS;
}