|
-
Oct 9th, 2004, 12:13 PM
#1
Thread Starter
Addicted Member
C Command Processing <Sorted>
Hi again
i want to make my application allow the user to enter set commands,
i cant seem to get it to use a switch statement to find out what was entered
here is an example
Code:
char cnd[4];
cnd = strncpy(cmddata,0,4);
switch(cnd)
{
case "HELP"
printf("here is a list of the commands");
case "STOP"
}
}
thanks again
Last edited by señorbadger; Oct 9th, 2004 at 01:44 PM.
-
Oct 9th, 2004, 12:16 PM
#2
Not NoteMe
You cannot use a switch statement with a char array, since it will comapre the pointers, not the data.
use if....else if statements and the strcmp function.
also, just FYI with a switch statement the code continues after the case statement, i.e. with the code you have it'd print that message, then do the code for "STOP". You need a break statement after it.
Quotes:
"I am getting better then you guys.." NoteMe, on his leet english skills.
"And I am going to meat her again later on tonight." NoteMe
"I think you should change your name to QuoteMe" Shaggy Hiker, regarding NoteMe
"my sweet lord jesus. I've decided never to have breast implants" Tom Gibbons
Have I helped you? Please Rate my posts. 
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
|