Hi, im just trying to compare a character(char) to a set list of characters (e.g. "a", "b", etc).
first i read in the value- (i have tried this two ways)
When i printf this value -
It outputs what it is supposed to,
Now for the actual error (of which there are a couple)
When i compare var_name to another character
e.g.
I get the following error cannot compare a const char to a char.
Then i read somewhere about adding an * to fix this problem (i thought this was a pointer by the way) -
And believe it or not it actually worked???, anyhow now its stopped working completely (e.g even though var_name = "z" it wont pick it up)
So my question to anyone who will help how do i compare a char to a character and have it work.
Any help in this matter is greatly appreciated, you have my thanks.
first i read in the value- (i have tried this two ways)
Code:
scanf("%c", &var_name); //also tried this and yes i know the difference scanf("%s", &var_name);
Code:
printf("%c this is var_name", var_name);
Now for the actual error (of which there are a couple)
When i compare var_name to another character
e.g.
Code:
char var_name; if (var_name != "z") { // code goes here }
Then i read somewhere about adding an * to fix this problem (i thought this was a pointer by the way) -
Code:
char *var_name; if (var_name != "z") { // code goes here }
So my question to anyone who will help how do i compare a char to a character and have it work.
Any help in this matter is greatly appreciated, you have my thanks.
Comment