any ideas on what's wrong with this segment? (it compiles in a program, but it doesn't work like it should)
Code:#define isalpha_alternate(x) (((x>='a' && x<='z')||(x>='A' && x<='Z')?1:0))
any ideas on what's wrong with this segment? (it compiles in a program, but it doesn't work like it should)
Code:#define isalpha_alternate(x) (((x>='a' && x<='z')||(x>='A' && x<='Z')?1:0))
Is it the braces?
#define isalpha_alternate(x) (((x>='a' && x<='z')||(x>='A' && x<='Z'))?1:0)
"Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
Friedrich Nietzsche
"I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
George Best
"If you are going through hell....keep going."
Winston Churchill
what are you aiming to acheive?
isalpha() already determine wether the data is a char,
if your aim is to print uppercase the char or print to lower case char's
first test for a char
main()
{
char ch;
printf("Enter a letter >");
scanf("%c", &ch);
if( ch == isalpha(ch))
{
toupper(ch);
//other test
}
else
printf("\nthe letter is not a character");
}
maybe!!
Before you judge a man, walk a mile in his
shoes. After that, who cares.. He's a mile away and you've got
his shoes.
************William Connoly
This works fine for me, be careful what kind of input you pass to the macro and put parens around the variables to ensure it works correctly with strange input.
-PreludeCode:#include <stdio.h> #include <stdlib.h> #define isalpha_alternate(x) ((x) >= 'a' && (x) <= 'z'||(x) >= 'A' && (x) <= 'Z') ? 1 : 0 int main(void) { char ch = 'M'; printf( "%d\n", isalpha_alternate( 'g' ) ); printf( "%d\n", isalpha_alternate( ch ) ); printf( "%d\n", isalpha_alternate( '7' ) ); return EXIT_SUCCESS; }
My best code is written with the delete key.