I have tried & tried & tried to figure out what's wrong with my code but I can't . I's supposed to give an error if the user enters anything else but an integer . So something like : 34j , should be comming up as an error.
Thanks for any help you can give !
Code:
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define MAXLINE 25
int check(char *line);
char line[MAXLINE];
int error,n,digit,flag;
int i = 0;
int flag = 0;
void main(){
do{
printf("Input a posetive integer: ");
if (fgets(line,MAXLINE,stdin) != NULL){
digit = check(&line);
error = ((sscanf(line,"/t%d/t",&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;
}