11-22-2001 03:06 AM
11-26-2001 10:43 AM
10-25-2010 10:22 AM
What of converting the strings to integers before doing the switch/case?
or what would be a good work around for something like the following?...
switch (atoi(myString)){
case (atoi("myCase")):
some code here;
break;
case (atoi("mySecondCase")):
some code here;
break;
}
10-25-2010 10:37 AM
Unfortunately your code cannot work: atoi converts the string representation of a number into its numerical equivalent. That is: atoi ("123") = 123; atoi ("myString") = 0!
In this environment the closer equivalent of a switch is a series of if:
if (!strcmp (myString, "myCase")) {
some code here;
}
else if (!strcmp (myString, "mySecondCase")) {
some code here;
}