i have a problem making a switch case read a string instead of just a number, if it's possible, I want it to read both. any advice on how to do that ? thanks
Asked
Active
Viewed 50 times
1
-
Do you want to compare a string with some possibilities using switch/case (and there is already an answer for that) ? Else please clarify because I do not understand what you say about 'read' – bruno Apr 04 '19 at 12:40
1 Answers
2
This is not possible: the case labels must be compile time evaluable integral types in C.
If you need anything else, then use an if
block, using strcmp
&c.
(Although some folk when writing non-portable code might use multicharacter constants as case labels: see This source code is switching on a string in C. How does it do that?)

Bathsheba
- 231,907
- 34
- 361
- 483
-
Write a complete c program that implements Queues with three functions a. Enqueue() b. Dequeue() c. Display() The program should take “strings” as user input. – Nicolas Porras Apr 04 '19 at 12:45
-
-
is there a way that i can show my code here? sorry first time posting here – Nicolas Porras Apr 04 '19 at 12:47
-
@NicolasPorras: I don't see any need for that. Why can't you use an `if` block as I suggested/ – Bathsheba Apr 04 '19 at 12:48