I am trying to receive a string of user input and write it to a file. No matter what I do, however, the output always has the spaces removed from the string.
I thought that the whole purpose of using gets()
/puts()
was that it would read/output all of the characters in a string until it encounters a newline character.
Can somebody please tell me what I am doing wrong??
int main (void){
char userInput[100];
char filename[50];
FILE *cfPtr;
printf("Enter name of file to open: ");
scanf("%s", &filename);
cfPtr = fopen(filename, "a+");
printf("Enter text to add to file: \n");
fgets(userInput, 100, stdin);
while (strcmp( userInput, "0") != 0) {
fputs( userInput, cfPtr);
fgets(userInput, 100, stdin);
} // end while
fclose( cfPtr );
system("pause");
} // end main