
atoi ( ) to return error if fail......
Dear All,
My code :-
************
fgets ( a, 50, stdin);
b=atoi (a);
printf("%d", b);
*************
1st run:-
12 (enter)
12 (displayed)
2nd run:-
12abc (enter)
12 (displayed)
Why? The truth is I entered 12ab, not 12. I want it to display error
message when it cannot convert the whole array into integer. Any
suggestion?
Tks.