The problem is that it should terminates after '^Z' but not '\n'.Code:#include <stdio.h> #include <stdlib.h> #define MAX 1000 int main() { FILE *outFile; char filename[50]; char message[MAX]; int i; printf("Please input a filename: "); gets(filename); outFile = fopen(filename,"r"); if (outFile == NULL) { outFile = fopen(filename,"w"); printf("\nThe file %s is created successfully!.",filename); printf("\n\nYou may start to input your message now!!\n"); printf("Please enter Control-Z when finished.\n\n"); gets(message); ****problems here**** } else { printf("\nThe file is currently exist."); printf("\nPlease enter another filename."); } fflush(stdin); getchar(); return 0; }
What should I add to make it work?