Write user input string to file in C
<p>My program needs to take a user's input and save it to an external file for future reference. Here is the basic outline of the code. </p>

<pre><code>void newActivity(FILE *foutput) {
    char name[31];
    char description[141];
    finput = fopen("activities.txt", "a");

    printf("\n What is the name of your activity (up to 30 characters):\n");
    fgets(name, sizeof(name), stdin);

    printf("\nEnter a brief description (up to 140 characters) of what %s is about:\n",
           fputs(name, stdout));
    fgets(description, sizeof(description), stdin);

    if (finput == NULL) {
        printf("\nCould not open file.");
        exit(1);
    }

    fprintf(foutfile, "%s\n", name);
    fprintf(foutfile, "%s\n", description);

    fclose(foutfile)
}
</code></pre>

<p>When I run a simple test program that only asks for a name and prints that name, all is good. It looks like this: </p>

<pre><code>int main() {
    char name[50];
    fprint("What is your name? ");
    fgets(name, sizeof(name), stdin);
    fputs(name, stdout);
    return 0;
}
</code></pre>

<p>Unlike the working test program, my program does not not take any input from the user before moving to the second <code>printf()</code> statement. It does read the strings within the <code>printf</code> statements, but return a value of <code>(null)</code>. </p>

<p>As for writing to the file, the two <code>fprintf</code> lines should do it, but I cannot confirm it as the input text has not been properly recorded. </p>

<p>This is a function declared outside of my <code>main()</code>. Does that make affect the situation? </p>