Switch

This is a discussion on Switch within the C Programming forums, part of the General Programming Boards category; This function should get input c then call correct function. but only thing works is displayoption with character O. I ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    32

    Switch

    This function should get input c then call correct function.
    but only thing works is displayoption with character O.
    I though I might wrote function call wrong, but the Q(quit) is not working also.
    If I put letters other then O, it says "segmentation fault(Core Dumped)".

    Code:
    while(i>0)
    {
    gets(userinput); /* Get User Input */
    
    /*Decode user input*/
    decodeinput(userinput);
    
    printf("C1= %c\n\n", c);
    
    /* Led to correct Function */
    switch(c)
    {
    	 		case 'I': /* Insert */
    				InsertCharacter(buffer, input2);
    				DisplayBuffer(buffer);
    				break;
    
    			case 'F': /* Forward */
    				MoveCursorForward(buffer);
    				DisplayBuffer(buffer);
    				break;
    
    			case 'B': /* Backward */
    				MoveCursorBackward(buffer);
    				DisplayBuffer(buffer);
    				break;
    
    			case 'D': /* Delete */
    				DeleteCharacter(buffer, num);
    				DisplayBuffer(buffer);
    				break;
    
    			case 'J': /* Home */
    				MoveCursorToStart(buffer);
    				DisplayBuffer(buffer);
    				break;
    
    			case 'E': /* End */
    				MoveCursorToEnd(buffer);
    				DisplayBuffer(buffer);
    				break;
    
    			case 'C': /* Copy */
    				CopyFromBuffer(buffer, num);
    				DisplayBuffer(buffer);
    				break;
    
    			case 'P': /* Paste */
    				PasteIntoBuffer(buffer);
    				DisplayBuffer(buffer);
    				break;
    
    			case 'T': /* Cut */
    				CutFromBuffer(buffer, num);
    				DisplayBuffer(buffer);
    				break;
    
    			case 'O': /* Display User options again */
    				printf("\n");
    				displayoptions();
    				DisplayBuffer(buffer);
    				break;
    
    			case 'Q': /* Quit The program */
    				i=0;
    				break;
    
    			default:
    				printf("\nInvalid Command!\n\n");
    				DisplayBuffer(buffer);
    				break;
    	} /* End Switch */
    }/* End While */

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    32

    maybe decoding again?

    hmm....
    maybe decoding causes the error??
    but the O works fine though..
    still don't get it why this program display "segmentation fault(core dumped) error"

    Code:
    /* Decode User Input */
    void decodeinput(char input[100])
    {
    
    char input3[100];
    
    strcpy(input3,input); /* Copy input to input3 */
    
    strupr(input3); /* Make command to upper case */
    
    if('0' < input[0] && input[0] <'9')
    num = input3;
    else 
    {   
    	c = input3[0]; /* Store first letter of array to a character c */
        num = 0;
    }
    
    
    
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Data Structure Eror
    By prominababy in forum C Programming
    Replies: 3
    Last Post: 01-06-2009, 08:35 AM
  2. ascii rpg help
    By aaron11193 in forum C Programming
    Replies: 18
    Last Post: 10-29-2006, 01:45 AM
  3. Switch
    By cogeek in forum C Programming
    Replies: 4
    Last Post: 12-23-2004, 05:40 PM
  4. Switch Case
    By FromHolland in forum C++ Programming
    Replies: 7
    Last Post: 06-13-2003, 03:51 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21