I can get the following code to error out when I put anything other than a number first, but if I input numbers first followed by a char it won't error out. For example: f431 causes an error but 431f will not. Should I attempt to use fscanf and if I should, how would I go about doing so/
Code:#include <stdio.h> int check(char *line); char line[MAXLINE]; int error, n, digit; int i = 0; int flag = 0; void main(){ do{ printf("Input a positive integer: "); if (fgets(line, MAXLINE, stdin) != NULL){ digit = check(&line[0]); error = ((sscanf(line," %d", &n) != 1 || n <= 0) && (digit == 1)); } if (error) printf("\nERROR: Do it again .\n"); else printf("There was no error!"); }while (error); } int check(char *line){ while((i < MAXLINE) && (flag == 0)){ if (isalpha((int)line[i])) flag = 1; ++i; } if (flag == 0) return 0; else return 1; }