C++: Crashes on trying to write to file
<p>new to C++. The purpose of the program is to give the user an option to open a file, write to it, then read the file that was just written to and display back what is now in the file. When it'll take in the user input, but after hitting enter it will crash. I think it's crashing when it tries to read the file?</p>

<pre><code>#include &lt;stdio.h&gt;
#define SIZE 80
#include &lt;iostream&gt;
int main(void)
{
FILE * pFile;
int c; // variable to hold character input by user
char sentence[SIZE]; // create char array
char filename[SIZE]; //create filename array
char filesentence[SIZE];
int i = 0; // initialize counter i
int number;
std::cout &lt;&lt; "Give a number. 1 for file. Anything else for standard.";
std::cin &gt;&gt; number;
getchar();




if(number==1)
{

    puts("Enter filename to append: ");
    while ((i &lt; SIZE-1) &amp;&amp; (c = getchar()) != '\n') {
    filename[i++] = c;}

    filename[i]= '\0';



    //fgetc(sentence,80,stdin);
    pFile=fopen(filename,"w+");

    puts("Give a sentence to place in file:");
    while ((i &lt; SIZE-1) &amp;&amp; (c = getchar()) != '\n') {
    sentence[i++] = c;}

    sentence[i]= '\0';

    fputs(sentence,pFile);

    i=0;
    do {
      c = fgetc (pFile);
      filesentence[i++] = c;
      printf(filesentence);   
    } while (c != EOF);

    fclose (pFile);


}
else
{

    // prompt user to enter line of text
    puts("Enter a line of text:");

    // use getchar to read each character
    while ((i &lt; SIZE-1) &amp;&amp; (c = getchar()) != '\n') {
    sentence[i++] = c;}

    sentence[i]= '\0';

    // terminate string
    // use puts to display sentence

    puts("\nThe line entered was:");
    puts(sentence);
}


}
</code></pre>