You don't need to change it. The compiler will implicitly convert your char
to an int
before passing it to isalnum
. Functions like isalnum
take int
arguments because functions like fgetc
return int
values, which allows for special values like EOF
to exist.
Update: As others have mentioned, be careful with negative values of your char
. Your version of the C library might be implemented carefully so that negative values are handled without causing any run-time errors. For example, glibc
(the GNU implementation of the standard C library) appears to handle negative numbers by adding 128 to the int
argument.* However, you won't always be able to count on having isalnum
(or any of the other <ctype.h>
functions) quietly handle negative numbers, so getting in the habit of not checking would be a very bad idea.
* Technically, it's not adding 128 to the argument itself, but rather it appears to be using the argument as an index into an array, starting at index 128, such that passing in, say, -57
would result in an access to index 71
of the array. The result is the same, though, since array[-57+128]
and (array+128)[-57]
point to the same location.