Hi! I know this has been raised so many times. But no recommendations from the previous questions worked for me...
I have 2 fgets() in a row:
Code:
printf("Please enter title:");
// Making sure we don't have newline character in the buffer
while (getchar() != '\n');
fgets(title, sizeof(title), stdin);
//Getting rid of newline character in the end
temp_len = strlen(title);
if (title[temp_len - 1] == '\n') {
title[temp_len - 1] = 0;
}
printf("title: |%s|", title);
printf("Please enter author:");
// Making sure we don't have newline character in the buffer
while (getchar() != '\n');
fgets(title, sizeof(authors), stdin);
//Getting rid of newline character in the end
temp_len = strlen(authors);
if (authors[temp_len - 1] == '\n') {
authors[temp_len - 1] = 0;
}
printf("authors: |%s|", authors);
If this matters, this all happens in a switch.
And here are the declaratiosn:
Code:
char title[100];
har authors[100];
I have also tried fflush(stdin), but the result was the same:
It lets me enter my string, but when I press ENTER it add newline but still requires me to press ENTER again and then it stops, as a result: empty string...
Thank you!