一鼓作气学文件函数
#include<stdio.h>#include<string.h>
int main(void)
{
FILE *fp;
char pathname[20];
char txt01[20]={'\0'};
char txt02[20]={'\0'};
int fileLen;
printf("Please type the path name of the file\n");
scanf("%s",pathname);
fp=fopen(pathname,"w");
printf("Please input a string to this file\n");
scanf("s%",txt01);
fileLen=strlen(txt01);
fwrite(txt01,fileLen,1,fp);
fclose(fp);
printf("The file has been saved\n");
printf("The content of the file : %s is\n",pathname);
fp=fopen(pathname,"r");
fread(txt02,fileLen,1,fp);
printf("%s\n",txt02);
return 0;
}
这个看了好久不知道哪里错了,编译没有错误,逻辑上感觉也没错误,那位大虾露一手啊,急切啊!!!