)

Posted 爱吃香蕉的猴子0000

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了)相关的知识,希望对你有一定的参考价值。

Hello, 大家好,我是爱吃香蕉的猴子,记录一下addaword.c程序


#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 40

int main(void)

    FILE *fp;
    char words[MAX];

    if((fp = fopen("words", "a+")) == NULL)
    
        fprintf(stdout, "Can't open words file.\\n");
        exit(1);
    
    puts("Enter words to add to the file: press the Enter press at the begining of a line to terminate.");

    while((fscanf(stdin, "%40s", words) == 1) && (words[0] != '#'))
        fprintf(fp, "%s\\n", words);

    puts("File contents:");
    rewind(fp);//返回到文件开始处读取
    while(fscanf(fp, "%s", words) == 1)
        puts(words);

    if(fclose(fp) != 0)
        fprintf(stdout, "Error closing file.\\n");

    return 0;

                                 Code的搬运工V1.0

以上是关于)的主要内容,如果未能解决你的问题,请参考以下文章