Why on earth would you think %s would work for an integer type? How many times do they have to tell you to stop scanning into an enum? Have you read anything we have written here?
Quzah.
Why on earth would you think %s would work for an integer type? How many times do they have to tell you to stop scanning into an enum? Have you read anything we have written here?
Quzah.
Hope is the first step on the road to disappointment.
Booleen is an enum type! There isn't room to hold a whole string like "vrai" in there! We went over this already. You need a temporary string to store the users input, then use strcmp like so:
You have to translate the string the user types into the right enum value. scanf won't do it for you. You have to translate the enum value into a string to print. printf won't do it for you.Code:typedef enum Booleen Booleen ; enum Booleen {faux,vrai}; int main (void) { Booleen b; char buf[50]; scanf("%s", buf); if (strcmp(b, "vrai") == 0) { b = vrai; } else { b = faux; } printf("The value of b is %s\n", b == vrai ? "vrai" : "faux"); return 0; }
Also, notice those two blue lines. It's int main(void) and return an int at the end (usually zero). Read about why this is important here: Cprogramming.com FAQ > main() / void main() / int main() / int main(void) / int main(int argc, char *argv[]).
So I must use string ... ok
thank you very much