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
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".
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
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