#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE* fp=fopen("D:/a.txt","r");
if(!fp) return -1;
char* p=(char*)malloc(sizeof(char*)*1024);
fscanf(fp,"%s",p);//读取文件中的内容,遇到换行和空格停止
printf("%s\n",p);
int a,b,c;
fscanf(fp,"%d+%d=%d",&a,&b,&c);
printf("%d %d %d\n",a,b,c);
free(p);
fclose(fp);
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int main()
{
FILE* fp=fopen("D:/b.txt","w");
if(!fp) return -1;
char ch[]="hello world";
fprintf(fp,"%s",ch);//向文件中写入数据
int a=10;
fprintf(fp,"%d",a);
fclose(fp);
return 0;
}