I have a program here that allows a user to append a text file among other features but I've just shown 2 to keep it simple. The problem is, when the user selects, say option no. 1, the "Append" & "Enter a sentence:" comes out fine but the program quits at that...i.e, before the user can enter the sentence, it quits. How do I fix this ? (I've tried a simpler example with scanf & printf statements which work but here i'm working with a file and am unable to get the input required!)
int main()
{
int choice;
char c[2000];
FILE *fp;
printf("Welcome to my Text Editor!\n");
printf("Enter the letter for the operation that you would like to carry out on the file\n");
printf("1 - Append a word to end of file\n");
printf("2 - Search for a word in the file\n");
scanf ("%d", &choice);
if (choice == 1)
{
printf ("Append\n");
fp=fopen("C:/Users/Asim/Desktop/random.txt","a");
if(fp==NULL){
printf("Error!");
exit(1);
}
printf("Enter a sentence:\n");
gets(c);
fprintf(fp,"%s",c);
fclose(fp);
}
else if (choice == 2)
{
printf ("Search");
}
else
{
printf ("Invalid choice!");
}
}