|
-
Feb 23rd, 2001, 10:27 PM
#1
Thread Starter
PowerPoster
I know how to do this in VB but not in VC++ 
Code:
Select Case BookName
Case "VB"
'//Do what ever I need here
Case "VC"
'//Do what ever I need here
Case "Java"
'//Do what ever I need here
Case "Others"
'//Do what ever I need here
End Select
I try this in VC++, & it seem not work as what I expected.
Code:
switch (BookName)
{
case 'VB':
'//Do what ever I need here
break;
case 'VC':
'//Do what ever I need here
break;
case 'Java':
'//Do what ever I need here
break;
case 'Others':
'//Do what ever I need here
break;
}
-
Feb 24th, 2001, 05:30 AM
#2
Monday Morning Lunatic
You can't. Since strings in C are arrays, you can't compare them like that. You need a long string of else ifs.
I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
-- Linus Torvalds
-
Feb 25th, 2001, 03:10 AM
#3
Addicted Member
The Switch statement can evaluate integer, long or char, but NOT variables (unlike the case statement in VB). Also, keep in mind that whichever case is evaluated to be true, the program will "jump" to that point AND CONTINUE TO EXECUTE ALL THE SUBSEQUENT CODES within the Switch statement (i.e. all the subsequent cases). If you don't want that to happen, you have to put a break after each case statement.
Hope this helps.
substring.
-
Feb 25th, 2001, 03:12 AM
#4
Addicted Member
Oops, I see that you know how to use break. =) But again, you cannot use Switch on variables.
substring.
-
Feb 25th, 2001, 03:32 AM
#5
Frenzied Member
Apart from what's been said already, you don't use the apostrophe ( ' ) character to denote strings; they should be surrounded by speech marks - "this is a string". The apostrophes should be used when you want the code for a single character, which you are entering as a literal. So you might have
char continue = 'y';
or
char newline = '\n';
Harry.
"From one thing, know ten thousand things."
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|