0
Who to check if an input is left blank
For example: int i; scanf("%d", &i); This will inquire user for an input. If this is left blank, this will generate error if used in any function. So how can i check if input is blank? (So that I can replace that with my error handler)
3 odpowiedzi
+ 1
When you use scanf but user does not input anything then scanf will return a negative value.
So you use use if statement to check if there was any input or not.
Example:
#include <stdio.h>
int main() {
int foo;
if (scanf("%d", &foo) > 0) {
printf("Input = %d", foo);
} else {
printf("No input");
}
return 0;
}
0
🔫 Rick Grimes does the same apply for 'char' value?
Like:
char test_char;