Hey, im currently programming a program which will create a html document with whatever text you desire, the only problem is, each time i want to give it bold and italic (for example) it creates the word i inputted and bolds it and then creates another one but this time with italic, for example :
What text would you like to enter ?
Hey
Enter a command : Bold
Enter a command : Italic
and it created it like this : HeyHey
sorry if its not so understanable...
Why not have another case where it is bold and italic?
You know how to nest those tags properly in HTML right?
<lies>
If so then it should be really straightforward.
Also you could certainly use switch statements with strings. A window procedure in the WINAPI is an example.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
switch(msg) // This does nothing... but you get the idea
{
case WM_CREATE:
break;
case WM_PAINT:
break;
case WM_RBUTTONDOWN:
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
Just put whatever constant you are comparing against inside of the parentheses of the switch.
Alright let me get this straight once and for all, you can't put non-int non-const variables into a switch expression but there are workarounds that let you do the same basic thing.
I now see the issue with the WINAPI example, after looking back.
If I remember right, Java initially didn't allow String in their switch so you had to do enum workarounds like the WINAPI case. I mistakenly thought that like java, c++ changed to support string.
I assume like always this hasn't happened because of C backwards compatibility issues.
I think DTSCode's workaround is also pretty nice. I must say this is the first time I have ever even thought about the type issues with switch statements, I guess I just glossed over it. This thread was very instructive.
Thats not true. I write all of my scripts the way op does. Its all whitespace so it doesnt matter
Vill wasn't talking about the whitespace, but the fact that the <I> </I> block needs to be entirely inside the <b> </b> block. If you look at the post Vill's responding to, you'll see that the OP has the tags in a messed-up order.
Well, if the OP had used the style suggested by Vill, then his/her error would have been easy to spot instantly.
Programmers don't bang on about code layout and indentation because we're obsessed with visual aesthetics. We do it because it helps you avoid mistakes.