Why does this part always gets skipped? Please help. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Why does this part always gets skipped? Please help.

I've been told that it's because of the newline and I should remove it but I'm not sure how to do it. This is the part where it jumps to the next fgets: printf("Enter first string: "); fgets (first_name, 100, stdin); printf("\n"); Code: https://code.sololearn.com/cLlmpbjn4kf9 *It's a long switch case, I'm using Dev C++

19th Feb 2021, 5:29 AM
aecliam
aecliam - avatar
5 Answers
+ 2
That's because strcat() is concatenating str1 and str2 and assigning the new concatenated string to str1. str2 is left unchanged. You then print the new str1 and then the unchanged str2 in lines 59 and 61. fflush() is fine to use too. str1 = first_name str2 = second_name
19th Feb 2021, 7:14 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Try adding a space after %d in your scanf to catch the trailing whitespace character '\n' scanf("%d ", &string_library);
19th Feb 2021, 6:48 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
Also change line 13 to; printf("Choose the String Function to demo: "); and line 59 to; printf("str1 = %s", first_name); This should get rid of the remaining warnings.
19th Feb 2021, 6:55 AM
ChaoticDawg
ChaoticDawg - avatar
+ 1
ChaoticDawg in line 56, I need both the first name and second name to print together but instead, the second name prints after str1 in devc++ also the fflush works too
19th Feb 2021, 7:09 AM
aecliam
aecliam - avatar
0
I printed a new str1 but it still prints like this str1 = Mike Santos
19th Feb 2021, 7:27 AM
aecliam
aecliam - avatar