I have a pointer ( *ascii ) which a pointer to a char and I want it is value as an int in order to make it an if statement like
if ( ascii == 32 || ((ascii > 96) && (ascii < 123)) {
}
This is not working, i would appreciate help
I have a pointer ( *ascii ) which a pointer to a char and I want it is value as an int in order to make it an if statement like
if ( ascii == 32 || ((ascii > 96) && (ascii < 123)) {
}
This is not working, i would appreciate help
Your code is not working because you are checking the value of the pointer (the memory address) not the value of the thing being pointed at. Remember a pointer is an address, you have to dereference it to get the value at that address.
Once dereferenced, you can simply do a comparison with a char type to those values:
char ascii_char = *ascii;
if ( ascii_char == 32 || ((ascii_char > 96) && (ascii_char < 123))
{
}
Just put a * before the variable name
if ( *ascii == 32 || ((*ascii > 96) && (*ascii < 123)) {
}
or just assign it to another variable and use it instead
int a = *ascii
if ( a == 32 || ((a > 96) && (a < 123)) {
}
If you are not referring to comparing just the first char but the number stored in that ascii pointer then use atoi() function to convert the char array to a number and then compare.
Why do you go for ASCII value?
Following would be more readable way:
char ascii_char = *ascii;
if ( ascii_char == ' ' || ((ascii_char >= 'a') && (ascii_char <= 'z'))
{
}