Results 1 to 2 of 2

Thread: C Command Processing <Sorted>

  1. #1

    Thread Starter
    Addicted Member señorbadger's Avatar
    Join Date
    Oct 2003
    Location
    Mud pools of wellingborough
    Posts
    193

    Resolved 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.

  2. #2
    Not NoteMe SLH's Avatar
    Join Date
    Mar 2002
    Location
    192.168.0.1 Preferred Animal: Penguin Reason for errors: Line#38
    Posts
    3,051
    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
  •  



Click Here to Expand Forum to Full Width