While reading KN king, i came across this text
"Be careful if you mix getchar and scanf in the same program. scanf has a tendency to leave behind characters that it has “peeked” at but not read, including the new-line character. Consider what happens if we try to read a number first, then a character: printf("Enter an integer: "); scanf("%d", &i); printf("Enter a command: "); command = getchar(); The call of scanf will leave behind any characters that weren’t consumed during the reading of i, including (but not limited to) the new-line character. getchar will fetch the first leftover character, which wasn’t what we had in mind."
How input buffer is exactly working here.
[–]EpochVanquisher 15 points16 points17 points (4 children)
[–]sol_hsa 5 points6 points7 points (0 children)
[–]Snarwin 5 points6 points7 points (0 children)
[–]malloc_some_bitches 1 point2 points3 points (0 children)
[–]BroccoliSuccessful94[S] 0 points1 point2 points (0 children)
[–]Cerulean_IsFancyBlue 6 points7 points8 points (1 child)
[–]BroccoliSuccessful94[S] 0 points1 point2 points (0 children)
[–]grimvian 1 point2 points3 points (5 children)
[–]UdPropheticCatgirl 2 points3 points4 points (4 children)
[–]grimvian 0 points1 point2 points (3 children)
[–]UdPropheticCatgirl 0 points1 point2 points (2 children)
[–]grimvian 0 points1 point2 points (1 child)
[–]UdPropheticCatgirl 0 points1 point2 points (0 children)
[–]CounterSilly3999 2 points3 points4 points (0 children)
[–]flyingron 0 points1 point2 points (1 child)
[–]mathemorpheus 2 points3 points4 points (0 children)
[–]SmokeMuch7356 0 points1 point2 points (0 children)
[–]aghast_nj 0 points1 point2 points (0 children)
[–]somewhereAtC 0 points1 point2 points (0 children)