I am trying to read 2 values and to check if they are numbers. I read them as char-arrays and then I check with the isdigit() function to see if they are numbers. If so, I transform them in integers by using the function atoi. The problem is that when I execute the program, I write any value for a and then it says "invalid data". It doesn't allow me to read the other variable - b. Where is the problem?
It's been so long since I have used atoi , I forgot how it works.
This is the example from the reference on this site.
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* atoi example */
int main ()
char szInput ;
printf ("Enter a number: ");
fgets ( szInput, 256, stdin );
i = atoi (szInput);
printf ("The value entered is %d. The double is %d.\n",i,i*2);
I've already seen that but it doesn't help me at all. You see that the argument of atoi is the pointer of that string. My problem is that atoi is not used, it doesn't allow me to read the second value, is a kind of buffer-problem or something like that.