I wrote this code:
char str[10];
while(1)
{
scanf("%d",str);
}
if given a char (‘a’ for example) the loop just keep on going without stopping and asking for more input (the scanf isn’t blocking suddenly)
why is that? 🙂
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Because
ais not a decimal integer. scanf will attempt to read it but fail and not advance it’s internal pointer, thus it will endlessly try to read the sameaas a decimal and fail.consider the following program:
if you enter
athe first scanf will fail and the second will read ‘a‘ intoc. This should explain the problem 🙂