Case Switch issue

This is a discussion on Case Switch issue within the C Programming forums, part of the General Programming Boards category; Hey Guys, Trying to create a case switch for my separate functions... Here it is: Code: switch(i) { case 0: ...

  1. #1
    Registered User
    Join Date
    Oct 2007
    Posts
    20

    Case Switch issue

    Hey Guys,

    Trying to create a case switch for my separate functions...

    Here it is:
    Code:
    switch(i)
    	    { 
    	    case 0: IScd(int argc, char *argv[]); break;
    	    case 1: IShelp();break;
    	    case 2: kill_main(int argc, char *argv[]); break;
    	    case 3: ISls(args); break;
    	    case 4: ISps(); break;
    	    case 5: ISpwd(); break;
    	    default: break;
    	     }
    All the functions are there BUT it wont compile: error: syntax error before "int"....

    Any ideas?

    I think Im doing it right...

  2. #2
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Quote Originally Posted by pc_doctor View Post
    Hey Guys,

    Trying to create a case switch for my separate functions...

    Here it is:
    Code:
    switch(i)
            { 
            case 0: IScd(int argc, char *argv[]); break;
            case 1: IShelp();break;
            case 2: kill_main(int argc, char *argv[]); break;
            case 3: ISls(args); break;
            case 4: ISps(); break;
            case 5: ISpwd(); break;
            default: break;
             }
    All the functions are there BUT it wont compile: error: syntax error before "int"....

    Any ideas?

    I think Im doing it right...
    To begin, see the red.

  3. #3
    Registered User
    Join Date
    Oct 2007
    Posts
    20
    Quote Originally Posted by master5001 View Post
    To begin, see the red.
    Ahh ok - so basically you cannot have Ints and Chars in the same thing....what way round it is there?

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    When you call a function, like say sin(5.5) -- you just pass the thing to the function, you don't go trying to tell the compiler what kind of thing it is. The compiler can see perfectly well for itself that argc is an int, you don't need to tell it so.

  5. #5
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Code:
    switch(i)
    { 
            case 0: IScd(argc, argv); break;
            case 1: IShelp();break;
            case 2: kill_main(argc, argv); break;
            case 3: ISls(args); break;
            case 4: ISps(); break;
            case 5: ISpwd(); break;
            default: break;
    }
    perhaps?

  6. #6
    Registered User
    Join Date
    Oct 2007
    Posts
    20
    Quote Originally Posted by master5001 View Post
    Code:
    switch(i)
    { 
            case 0: IScd(argc, argv); break;
            case 1: IShelp();break;
            case 2: kill_main(argc, argv); break;
            case 3: ISls(args); break;
            case 4: ISps(); break;
            case 5: ISpwd(); break;
            default: break;
    }
    perhaps?
    That gives the complier error:

    sample2.c:93: error: `argc' undeclared (first use in this function)
    sample2.c:93: error: (Each undeclared identifier is reported only once
    sample2.c:93: error: for each function it appears in.)
    sample2.c:93: error: `argv' undeclared (first use in this function)

  7. #7
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Well, presumably you know what you want to pass to IScd and ISls and so on; so do so. If you want to use the command line arguments, then make sure you put argc and argv in the declaration of your main() function.

  8. #8
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Posts
    22,920
    pc_doctor, I find it perfectly logical that you must pass existing variables or values to a function.
    Can you give someone a fruit that you do not have? No! Then why should a compiler be able to call a function with variables or values that do not exist?
    Think about it!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #9
    Registered User
    Join Date
    Oct 2007
    Posts
    20
    Quote Originally Posted by Elysia View Post
    pc_doctor, I find it perfectly logical that you must pass existing variables or values to a function.
    Can you give someone a fruit that you do not have? No! Then why should a compiler be able to call a function with variables or values that do not exist?
    Think about it!
    Lol - Yeah i know...Im blaming it on not enough sleep and getting stressed about all these elements of my program...

    LS,
    KILL,
    PS,
    PWD,
    CD

    All combined into a shell.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. function switch help
    By etbjr182 in forum C Programming
    Replies: 9
    Last Post: 02-20-2009, 03:51 PM
  2. Intel syntax on MinGW ?
    By TmX in forum Tech Board
    Replies: 2
    Last Post: 01-06-2007, 09:44 AM
  3. Keypress reading
    By geek@02 in forum Windows Programming
    Replies: 1
    Last Post: 06-16-2004, 01:16 PM
  4. opengl program as win API menu item
    By SAMSAM in forum Game Programming
    Replies: 1
    Last Post: 03-03-2003, 07:48 PM
  5. enumeration with switch case?
    By Shadow12345 in forum C++ Programming
    Replies: 17
    Last Post: 09-26-2002, 05:57 PM

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