switch is broken

This is a discussion on switch is broken within the C++ Programming forums, part of the General Programming Boards category; ok i have a problom... my program quits even tho im sure that its fine... no iv been mucking around ...

  1. #1
    Registered User PanzTec's Avatar
    Join Date
    Sep 2004
    Posts
    24

    switch is broken

    ok i have a problom... my program quits even tho im sure that its fine... no iv been mucking around with it(crappy code) here it is

    Code:
    #include "stdafx.h"
    
    void command (int pram)
    {
    	char cmd[256];
    	printf("Evil Command Center->");
    	scanf("%s",cmd);
    	proc(cmd);
    }
    
    void proc(char cmd[256])
    {
    	int fn; //function so the switch will work
    	if (!strcmp(cmd, "help"))
    	{
    		fn = 1;
    	} else if (!strcmp(cmd, "exit"))// to cheack out if its time to quit
    	{
    		fn = 2;
    	}
    
    	switch(fn)
    	{
    	case 1:				//help system
    		{
    			system("help");
    		}break;
    	case 2:
    		{
    			Fquit();
    		}break;
    	default:
    		{
    			printf("unknown command\n");
    		}break;
    		command(0);
    	}
    	
    }
    
    void Fquit()
    {
    	system("exit");
    }
    The Matrix Will Live Again!

  2. #2
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    Quote Originally Posted by PanzTec
    ok i have a problom... my program quits even tho im sure that its fine... no iv been mucking around with it(crappy code) here it is
    yea, you're right...the switch statement is broken....

    you better get a new compiler
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

  3. #3
    Registered User PanzTec's Avatar
    Join Date
    Sep 2004
    Posts
    24
    i use VC6 iv tryed dev and that doesnt compile any code i make for it
    The Matrix Will Live Again!

  4. #4
    Registered User PanzTec's Avatar
    Join Date
    Sep 2004
    Posts
    24
    wait wait... i was talking about the program closing down! lol not the compiler
    The Matrix Will Live Again!

  5. #5
    Registered User
    Join Date
    Mar 2003
    Location
    UK
    Posts
    169
    What 'misplaced' is telling you is that there's nothing wrong with the switch statment!

    > command(0);

    This line will not do anything i.e it will never be executed because its in the wrong place.

    What I think you're trying to do is call command() in recursion to loop back which is the wrong method to use. Use a 'while' or 'do while' loop.

  6. #6
    Registered User
    Join Date
    Sep 2004
    Posts
    719
    Quote Originally Posted by Scarlet7
    What 'misplaced' is telling you is that there's nothing wrong with the switch statment!

    > command(0);

    This line will not do anything i.e it will never be executed because its in the wrong place.

    What I think you're trying to do is call command() in recursion to loop back which is the wrong method to use. Use a 'while' or 'do while' loop.

    actually....i was saying put command(0) someplace where it will get executed.....

    default: command(0); break;

    instead of

    default: break; command(0);
    i seem to have GCC 3.3.4
    But how do i start it?
    I dont have a menu for it or anything.

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