代码:

#include <stdio.h>
#include <string.h>

#define N 1024


int main(int argc, char* argv[])
{
    FILE* fp;
    fp = fopen("file.txt", "w");
    if(!fp){
        printf("file open failed.");
        return 0;
    }

    char c;
    printf("please input a string end with #:/n");
    c = getchar();
    while(c != '#'){
        fputc(c, fp);
        c = getchar();
    }

    fclose(fp);

    return 0;
}