1.fprintf 和 fscanf
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/bbbf5631d5f6acdab85e9d222f754759.png)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/a9cc03fb1876abf2240b649c332537a9.png)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/379d7a089825921f22ea42d3496c93f8.png)
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/af4d2687adda4bfdd171c006c82bd8d1.png)
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
void write_file()
{
FILE* fp = fopen("abc.c", "w");
if (!fp)
{
perror("fopen error");
return;
}
fprintf(fp, "%d\n", 10);
fprintf(fp, "%d\n", 8);
fprintf(fp, "%d\n", 6);
fclose(fp);
}
void read_file()
{
int a;
FILE* fp = fopen("abc.c", "r");
if (!fp)
{
perror("fopen error");
return;
}
fscanf(fp, "%d\n", &a);
printf("%d\n", a);
fscanf(fp, "%d\n", &a);
printf("%d\n", a);
fscanf(fp, "%d\n", &a);
printf("%d\n", a);
fscanf(fp, "%d\n", &a);
printf("%d\n", a);
fclose(fp);
}
void read_file2()
{
int a;
FILE* fp = fopen("abc.c", "r");
if (!fp)
{
perror("fopen error");
return;
}
while (1)
{
fscanf(fp, "%d\n", &a);
printf("%d\n", a);
if (feof(fp))
break;
}
fclose(fp);
}
void read_file3()
{
char buf[1024];
FILE* fp = fopen("abc.c", "r");
if (!fp)
{
perror("fopen error");
return;
}
while (1)
{
fgets(buf, 1024, fp);
if (feof(fp))
break;
printf("%d\n", buf[0]);
}
fclose(fp<