#include <stdio.h>
#include <stdlib.h>
int main() {
FILE
char filename[] = "ex5.txt";
char content[] = "This is a file created by ex5.c";
// 写入文件
fp = fopen(filename, "w");
if (fp == NULL) {
printf("File creation failed.\n");
exit(1);
}
fprintf(fp, "%s\n", content);
fclose(fp);
// 读取文件
char readContent[100];
fp = fopen(filename, "r");
if (fp == NULL) {
printf("File opening failed.\n");
exit(1);
}
fscanf(fp, "%s", readContent);
fclose(fp);
printf("The content of the file is: %s\n", readContent);
return 0;
}
</stdlib.h></stdio.h>
暂无评论