2 Replies - 649 Views - Last Post: 23 March 2011 - 09:29 AM Rate Topic: -----

#1 sidebrok  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 61
  • Joined: 28-October 10

switch with string case?

Posted 23 March 2011 - 09:13 AM

Does anyone know how i can make a switch with string cases like this :

char *mystring
printf("write something:\n");
scanf("%s", mystring);
switch (mystring) {
case "hey": case "hey!":
printf("hello");
break;
}


Is This A Good Question/Topic? 0
  • +

Replies To: switch with string case?

#2 musiliu  Icon User is offline

  • D.I.C Head

Reputation: 8
  • View blog
  • Posts: 110
  • Joined: 04-December 09

Re: switch with string case?

Posted 23 March 2011 - 09:23 AM

i don't think you can..

i looked at a website and you can do this:

Not directly. Sometimes, it's appropriate to use a separate function to map strings to integer codes, and then switch on those: 

Was This Post Helpful? 0
  • +
  • -

#3 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,496
  • Joined: 23-August 08

Re: switch with string case?

Posted 23 March 2011 - 09:29 AM

You can only use integer types in a switch.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1