#include <stdio.h>
int main()
{
FILE *fp = NULL;
char str[50] = {0};
fp = fopen("c:\\a.txt","w");
if(fp==NULL)
{
printf("file write error!\r\n");
return -1;
}
fputs("hello world!\n",fp);
fclose(fp);
fp = NULL;
fp = fopen("c:\\a.txt","r");
if(fp==NULL)
{
printf("file read error!\r\n");
return -2;
}
fgets(str,sizeof(str),fp);
fclose(fp);
printf("%s",str);
return 0;
}
![](https://video.ask-data.xyz/img.php?b=https://iknow-pic.cdn.bcebos.com/3801213fb80e7bec47a9570c242eb9389a506bef?x-bce-process=image%2Fresize%2Cm_lfit%2Cw_600%2Ch_800%2Climit_1%2Fquality%2Cq_85%2Fformat%2Cf_auto)