[Solved]Strange behavior of scanf in c language
I made a program which takes int inputs until you enter 1 and prints total number of inputs you've entered. This works fine. Ie for 3 4 1 output is 3, for 5 4 6 7 1 output is 5 ... https://code.sololearn.com/cEaA4MW1703u/?ref=app [code 1] But when I made same program to take char inputs until you enter 'a', gives totally wrong answer. Ie. For g h a output is 5 , for k f h r d a output is 11.. https://code.sololearn.com/c2ChayXblY61/?ref=app [code 2] But more strange thing happens when I combine both programs in one, the output of char inputs is still wrong and it don't even match with previous program's [code 2] output when given same inputs. Ie for 3 4 1 g h a output is 3 int and 6char for 5 4 6 7 1 k f h r d g output is 5 int and 12char https://code.sololearn.com/cpqNJtHXcIT0/?ref=app [code 3] Now if I make same program in c++ (by changing scanf printf with cin cout) Program works just fine. https://code.sololearn.com/c3Jtcbh2Y9Ru/?ref=app [code 4] What's wrong? What am I missing?