I don't understand how this function works!!! and specialy the "if condition" and it's return!!!!
please help!!!!
-
Boolean UserSaysYes(void)
-
{
-
int c;
-
printf("(y,n)?");
-
do{
-
while((c = getchar()) == '\n')
-
;
-
if(c == 'y' || c == 'Y' || c == 'n' || c == 'N')
-
return(c == 'y' || c == 'Y');
-
printf("please respond by typing one of the letters y or n\n");
-
}while(1) // this one also !!!!!
-
}
-
Hi momotaro,
The "if" condition checks whether the character entered is one among y,Y,n,N. If the character is one among the specified ones then the return statement is executed, otherwise the printf statement is executed.
Coming to the return statement: here the character entered is compared with y and Y. If it is one among the two then true(1) is returned, otherwise false(0) is returned to the calling function.
i.e., If the character entered is y or Y then it'll be "return 1", and if its n or N then it'll be "return 0".
I hope this helps you.
Regards,
Pradeep