Switch Command

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Switch Command

1,928 次查看
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
标签 (1)
0 项奖励
2 回复数

424 次查看
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 项奖励

424 次查看
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 项奖励