#include<stdio.h>
#include<string.h>
int main()
{
FILE *fp;
char readBuf[128]={
0};
char *buf="nice move!";
fp=fopen("./qin.txt","w+");//最后权限这儿一定用双引号(指针)
fwrite(buf,sizeof(char),strlen(buf),fp);
fseek(fp,0,SEEK_SET);
fread(readBuf,sizeof(char),strlen(buf),fp);
printf("%s\n",readBuf);
return 0;
}
用下面的代码也可以实现:
#include<stdio.h>
#include<string.h>
int main()
{
FILE *fp;
char readBuf[128]={
0};
char *buf="nice move!";
fp=fopen("./qin.txt","w+");
fwrite(buf,sizeof(char),strlen(buf),fp);
// fwrite(buf,sizeof(char)*strlen(buf),1,fp);//任取一种
fseek(fp,0,SEEK_SET);
// fread(buf,sizeof(char),strlen(buf),fp);
fread(readBuf,sizeof(char)*strlen(buf),1,fp);//任取一种
printf("%s\n",readBuf);
return 0;
}