Hi. Can i get explanation in C programming what does "1" mean in this line "if (scanf ("%d", &number) == 1)" or in this line "if (scanf("%19s", word) == 1)"
I want to understand the connection of 1 on those line. I tried to change them to 0 or 2 but program ended. So what's with 1?
I'm confuse with the 1 in thing line. Please help.
Post a Reply
|Oldest Newest Rating|
· August 25, 2015
scanf returns the number of successfully matched inputs. for example, consider the following:
if the user inputs a number, ret will 1. if the user inputs anything that isn't a number, ret will be 0.
now consider this:
if the user enters in a number and then a character in that order, ret will be 2. if the user enters something that's not a number and then a character, ret will be 1.
if the user enters a string, ret will be 1, otherwise it will be 0.
if the user enters in the corresponding data correctly in order, then ret will be 4. otherwise it will be less than 4.
One of the most popular languages of all time.
|Bucky Roberts Administrator|