1

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

Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
  • 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 Answers1

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