shaik786, your example won't work too well, I'm afraid. The contents of the str array is unknown, and you only place 1 character in it with getch(). This means the rest of the array could be anything, including other valid numbers.
Then, when you call atoi(), it will convert the whole array, not just the first byte.
Use something like this:
Code:
#include <stdio.h>
int main(void)
{
int i;
if (scanf("%d", &i) != 1)
{
printf ("Bad number!\n");
return 1;
}
printf ("i is %d\n", i);
return 0;
}
OR
Code:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int i;
char buffer[1024];
if (fgets(buffer, 1024, stdin) != NULL)
{
printf ("Number is %d\n", atoi(buffer));
}
return 0;
}