I used this macro:
#define ISALPHA(text[i]) ('a'<=a && a<= 'z')|| ('A'<=a && a<= 'Z')? ("alpha"):("not alpha")
It gives this error: [Error] "[" may not appear in macro parameter list.
How to give an array value as a parameter in macros in C?
There are multiple bugs in your code, but the answer to the headline question is that you use a plain name in the macro argument list:
#define ISALPHA(c) ((('a' <= (c) && (c) <= 'z') || \
('A' <= (c) && (c) <= 'Z')) ? "alpha" : "not alpha")
You then invoke the macro on array elements using:
ISALPHA(text[i])
Note the extensive use of parentheses in the macro to avoid problems with odd-ball macro arguments.
Much better than all that testing, though, would be to use the standard (locale-sensitive) isalpha() macro from <ctype.h>:
#define ISALPHA(c) (isalpha(c) ? "alpha" : "not alpha")
Bugs in your version include:
text[i] instead of a in the macro arguments.a in parentheses.Enclosing the strings in parentheses was unnecessary, but was not going to cause any trouble.
My choice to use c as a mnemonic for 'character' is stylistic or personal preference; using a consistently (for 'alphabetic', presumably) would be fine too.
Why don't you use isalpha declared in ctype.h. It's much more safer than using macros. Don't get me wrong, macros are fine tools, provided that you know what you are doing but often enough you can end up with undefined behaviour and you don't realize it.
I've seen things like this (in 3rd party libraries)
#define min(x,y) ((x)<(y)?(x):(y))
that seems OK, but it's not. Later when you don't think what you are doing, you could do something like this:
int something(int x, int y)
{
return min(x++, y);
}
which expands to
int something(int x, int y)
{
return ((x++)<(y)?(x++):(y));
}
and yields undefined behaviour.
isalpha? In any casetext[i]should be in the macro invocation, not its definition.#define ISALPHA(a) ...