Hello!
I'm writing a function to read input, and i want to have only numbers, so I used the function isdigit(). I then tested it out and the caracter '»' somehow seems to be considered a digit.
The code I have here is not the one I'm writing, is just a test to see if i can correct it. I wrote an if statement to get rid of the '»' caracter but it doesn't work, and i can't see why.
Hope you can help.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char string[20];
int stringlenth = 0;
for ( ; ; )
{
string[stringlenth] = getchar();
if (string[stringlenth] == '\n')
{
string[stringlenth] = '\0';
break;
}
if (isdigit(string[stringlenth]) != 0)
{
if (string[stringlenth] == '»') //this should get rid of the caracter... but it doesn't
{
continue;
}
printf ("%c" , string[stringlenth]);
++stringlenth;
}
}
return 0;
}