Why in my code , isdigit()
function dont work , when i print sum
it is 0?
p.s i include <ctype>
lib
int main(void)
{
int sum = 0;
int prvi = 0;
int drugi = 0;
prvi = 1;
drugi = 2;
if ( isdigit(prvi) && isdigit(drugi) )
sum = prvi + drugi;
printf("sum: %d \n",sum);
}
isdigit
is used to check whether a character is a decimal digit - it's unclear to me what character repertoire is used, but I don't know of any character repertoires in which 1 and 2 are characters. Try 48 and 49 for example, which are the ASCII values for '0' and '1'. Those should both make isdigit
return a non-zero result, at least if it's using ASCII.
If you don't have textual data, you don't need to call isdigit
. It's not clear what you're really trying to achieve, but I suspect isdigit
is a red herring...
See more on this question at Stackoverflow