实践过程截图,遇到问题GPT求解,代码链接

#include <stdio.h>

int main() {
    FILE *file;
    file = fopen("er.txt", "w");
    if (file == NULL) {
        printf("Cannot open file\n");
        return 1;
    }

    fprintf(file, "Hello, World!\n");
    fclose(file);
    file = fopen("er.txt", "r");
    if (file == NULL) {
        printf("Cannot open file\n");
        return 1;
    }
    char line[100];
    while (fgets(line, sizeof(line), file) != NULL) {
        printf("%s", line);
    }

    // 关闭文件
    fclose(file);

    return 0;
}

 

posted @ 2023-09-16 21:40  20211106隋吉达  阅读(23)  评论(0)    收藏  举报