Switch Command

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Switch Command

2,158 Views
scotty5555
Contributor I
Hi,
 
I am new to embedded software programming and using Codewarrior.I have done some c++ and turbo c programming before.
 
I am trying to program the mc9s12e128 chip.
 
The first question i have is regarding the switch statement.See below.
 
switch(rx_msg[0])
{
 case ('h'):sendmessage(tx_msg_1):break;
 case ('s'):sendmessage(tx_msg_2):break;
 default:sendmessage(tx_msg_3);
}
 
Is this the correct syntax for the switch statement which does complie ? 
 
Normally if using C builder for a console program i would use:     case 'h':sendmessage(    ):break;
But this format does not compile thats why i added the brackets : case ('h'):....  and it now it compiles.
 
Also is the correct include file for the switch statement : #include <stdlib.h> ?
Where would i find information regarding which include file is needed for certain commands ?
 
Can anyone help ?
 
Thanks,
 
Scotty5555
Labels (1)
0 Kudos
Reply
2 Replies

654 Views
J2MEJediMaster
Specialist I
Try:

Code:
switch(rx_msg[0]){ case 'h':   sendmessage(tx_msg_1); break; case 's':   sendmessage(tx_msg_2); break; default:   sendmessage(tx_msg_3); break;}

Note that you only use the colon to flag the end of the case statement.


Message Edited by J2MEJediMaster on 2008-04-02 09:37 AM
0 Kudos
Reply

654 Views
scotty5555
Contributor I
Sorry the colon mistake was when i typed it out...Below is what i had and compiles.
 
switch(rx_msg[0])
{
 case ('h'):sendmessage(tx_msg_1);break;
 case ('s'):sendmessage(tx_msg_2);break;
 default:sendmessage(tx_msg_3);
}
 
I will try what you suggest and see what happens.
Thanks,
             Scotty5555
0 Kudos
Reply