求助!!!!C语言高手一个小问题(急在线等!!!)

来源:百度知道 编辑:UC知道 时间:2024/06/01 05:28:38
本人初学者,对文件一窍不通,请问我想用文件写入和读出一个字符串:“the result of last game : computer win”
要怎么做????

#include <stdio.h>
#include <memory.h>
#define SIZE 50
void main()
{
char str[SIZE] = "the result of last game : computer win";
FILE *fp = fopen("data.txt", "w+");
fputs(str, fp);
memset(str, 0, SIZE);
rewind(fp);
fgets(str, SIZE-1, fp);
puts(str);
fclose(fp);
}

#include<stdio.h>
main()
{FILE *fp;
char a[100]="the result of last game : computer win",b[100];
fp=fopen("d://www.txt","w");
fprintf(fp,"%s",a);
fclose(fp);
fp=fopen("d://www.txt","r");
fscanf(fp,"%s",b);
fscanf(stdout,"%s",b);
fclose(fp);
}

哦, 对了,用fprintf和fscanf可以实现