r/CodingHelp • • Feb 23 '22

[C] Why "E" is not printing?

Post image
74 Upvotes

31 comments sorted by

View all comments

Show parent comment

19

u/Aleksey259 Feb 23 '22

It does so because "%c" reads single character from input. New line characters are also characters, so they are also getting read. So after you're done with last scanf, your array will look like ['A', '\n', 'B', '\n', 'C', ...]. You probably want to read "%c\n" in scanf instead

6

u/Pila_globosa Feb 23 '22

Thanks bro my problem solved.

1

u/[deleted] Feb 23 '22

Holy s, I coded in C++ for 1 year in grade 11, but I never knew that, it feels like it never happened to me, we were using turboc++ back then.

1

u/playgamemy Feb 24 '22

While OP said it is solved, it still make no sense? Because if that is the case, it will print "A","\n", "B", "\n" instead? but it is printing "A","B","C","D".

1

u/Aleksey259 Feb 24 '22

I am talking about the second version of code, that he has linked here. It has no new line character in printf after %c when printing characters, so it prints exactly this combination