I'm making function working like
Input contains : “1 2 3 4 5 6 7 8 9 10\n”
Function Outputs: “{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}\n”
I want to take a look how getchar() works, so I wrote the function like this:
int c ;
printf("{");
while ((c = getchar()) != EOF) {
printf("%c, ", c);
getchar();
}
getchar();
printf("}\n");
and when I put "1 2 3 4 5 6 7 8 9 10\n”, it comes like:
{1, 2, 3, 4, 5, 6, 7, 8, 9, 1,
, }
I guess something wrong with buffers inside. Maybe getchar() reads and out character by character so that 10 is considered as 1 and 0 separately?
I looked up some past questions,, but I didn't get it. Thanks for your insight.