I am trying to determine if every character in my string is alphanumeric. My compiler does not have the isalnum function.
My function is below and my_struct has a char array of size 6 (uint8 bom_pn[6]) ….and yes uint8 is a char.
boolean myfunc( my_struct * lh )
{
ret = ( isalphanum( lh->bom_pn ) && isalphanum( lh->bom_pn + 1 ) &&
isalphanum( lh->bom_pn + 2 ) && isalphanum( lh->bom_pn + 3 ) &&
isalphanum( lh->bom_pn + 4 ) && isalphanum( lh->bom_pn + 5 ) );
}
My macro definition is below:
#define isalphanum(c) ( ( c >= '0' && c <= '9' ) || \
( c >= 'A' && c <= 'Z' ) || \
( c >= 'a' && c <= 'z' ) )
The above throws the error “operand types are incompatible (” uint8 * ” and ” int “)”
If I change my definition to the following, my code compiles and I get warnings.
#define isalphanum(c) ( ( (uint8)c >= '0' && (uint8)c <= '9' ) || \
( (uint8)c >= 'A' && (uint8)c <= 'Z' ) || \
( (uint8)c >= 'a' && (uint8)c <= 'z' ) )
Warning: “conversion from pointer to smaller integer”
My question is, how do I properly create this definition without warnings (and obviously check correctly).
Thanks
As you said
lh->bom_pnis an array of bytes, which means it is effectively a pointer.So when you pass it to
isalphanum, you’re passing a pointer, and comparing it to literal bytes.You have two options:
1.)
2.)
Either one should fix your problem.