The following code lets the user write a number in a string so it will be converted to an integer automatically. However, if he writes something else than a number there should be an error. So far so good it worked.
The problem is now: I need to point an arrow to the letter which is not allowed by the user. Example: He writes 45. This is right. He writes 423a4. This is wrong. Then there should be an arrow point on the letter a.
But I don't know how and where I should put the arrow.
NOTE: NO LIBRARY FUNCTIONS ALLOWED except stdio.h
Here is the code:
#include <stdio.h>
void main()
{
char input[100];
printf("Type a String which will be converted to an Integer: ");
scanf("%s", input);
int number = 0;
int i = 0;
int x = 0;
bool success = true;
while (input[i] != '\0')
{
if (input[i] >= '0' && input[i] <= '9')
{
number = number * 10 + input[i] - '0';
i++;
}
else
{
success = false;
printf("\n");
printf("Character %c is not a number! \n", input[i]);
break;
}
}
if (success)
{
printf("string %s -> number %d \n", input, number);
}
}