写入file.txt
#include <stdio.h>
int main() {
FILE *fp;
fp = freopen("file.txt", "w+", stdout);
printf("该文本重定向到 file.txt\n");
fclose(fp);
return 0;
}
读取
#include<stdio.h>
int main() {
FILE *fp;
int c;
fp = fopen("file.txt", "r");
while (1) {
c = fgetc(fp);
if (feof(fp)) {
break;
}
printf("%c", c);
}
fclose(fp);
return (0);
}
Comments | 0 条评论