"I cannot stop my program until I enter two numbers when using scanf("%d\n",&i); "
Although this format allows scanf to read the number and store it in i , this βreadingβ continues and continues until a character with no spaces is found, followed by \n . That is why input 1 2 stops this scanf .
In this case, you should not specify a new line in the input format. Use scanf("%d",&i); instead .
source share