這樣寫也行:
#include <stdio.h>
#include <stdlib.h>
int main(void){
FILE *fp;
char str[200],ch;
int i;
fp=fopen("test","wb");
gets(str);
fwrite(str,sizeof str,1,fp);
fclose(fp);
fp=fopen("test","rb");
for(i=0;i<strlen(str);i++)
{
fread(&ch,sizeof ch,1,fp);
putchar(ch);
}
fclose(fp);
return 0;
} |