I have gone through many questions and blogs and books, but I guess I'm just not able to relate things properly. What does scanf do after scanning? It reads everything except space, tab and newline, but what does it do to newline?? I'm unable to remove newline any way after scanning input. For example, consider this as input:-
5
Abcdefgh
Now, I have scanned 5 as integer,
scanf("%d", &i);
but how do I remove '\n' in order to read everything ahead one character at a time? I want to use:-
while((c=getchar())!='\n'){//Do something}
The '\n' is supposed to be the one AFTER the string, but getchar() gets the one after 5 and loop terminates before even running once. I guess I'm just missing a very little trick.
scanf("%d", &i);
while((c=getchar())!='\n'){
//Do something with the character
}
Input File:-
5
ABCDEF
Expecting while loop to run, while it doesn't run. Because it catches '\n' after 5. I have tried adding getchar() in between scanf() and while(), but then program stucks and does nothing.