一道 文件有关的c语言题目 将"hello world!"写入文本文件file.txt,然后从file.txt中读出内容,并打印.

如题所述

#include <stdio.h>
int main()
{
    char s[20];
    FILE *fp;
    fp=fopen("file.txt", "w");
    if(fp == NULL) return 0;
    fprintf(fp, "%s", "hello world!");
    fclose(fp);
     
    fp=fopen("file.txt", "r");
    if(fp == NULL) return 0;
    fscanf(fp, "%s", s);
    fclose(fp);
     
    printf("%s", s);
    return 0;
}
温馨提示:答案为网友推荐,仅供参考
相似回答