Thread: in function 'main'

  1. #1
    Registered User
    Join Date
    Jun 2003
    Posts
    3

    Question in function 'main'

    $ cat shell.c
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    void sh(char *);
    int main()
    {
    void sh(char *cmd)
    int num;
    num = system(cmd);
    }

    $ gcc shell.c
    shell.c: In function `sh':
    shell.c:9: parse error before "num"
    shell.c:8: parm types given both in parmlist and separately
    $
    What do I do to correct this error??
    Last edited by zmonc; 06-12-2003 at 03:33 PM.

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,490
    I don't know... why are you writing this program? What is sh? What is cmd for?

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826

    Re: in function 'main'

    Originally posted by zmonc
    $ cat shell.c
    int main(void)
    {
    void sh (char *);
    void sh (char *cmd);
    int num;
    num = system(cmd);
    }
    1) Why do you have 'sh' defined twice?
    2) You have no variable named 'cmd'.
    3) You don't define the 'sh' function.

    There are your problems and your fixes.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User
    Join Date
    Jun 2003
    Posts
    3

    in function 'main'

    sorry...I am newbie
    I have modifed the code and compiled and got the new error message:

    $ cat shell.c
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    void sh(char *);
    int main()
    {
    void sh(char *cmd)
    int num;
    num = system(cmd);
    }

    $ gcc shell.c
    shell.c: In function `sh':
    shell.c:9: parse error before "num"
    shell.c:8: parm types given both in parmlist and separately
    $


    what's wrong in this now?

  5. #5
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    Use code tags, also few problems:

    >>void sh(char *);
    >>void sh(char *cmd)

    First you defined, now you didn't write the function, do something like this, first declare the function, then write it, or write it outside 'main'. Your main function doesn't return anything, before you close the main function (before the '}') return a value using 'return' like 'return 0;'.

  6. #6
    Registered User
    Join Date
    Jun 2003
    Posts
    3

    function sh

    thank you verymuch guys

  7. #7
    and the Hat of Clumsiness GanglyLamb's Avatar
    Join Date
    Oct 2002
    Location
    between photons and phonons
    Posts
    1,110
    First of all when you code you have to have a goal, what do you wont to do with this program. Ask yourself that and then come back, if we dont know your intentions then we cant know your problem...

    But if i were you i would start with searching a tutorial on the net...(there are plenty of them -- + you could visit the faq board of this site once in a while).

    Then to get to your code
    Why do you include header files such as stdlib and string.h i dont see any file or string handling in your code...
    Second of all Check your compiler errors-also compiler warnings because they may indicate that something nifty is going on in your code.
    [quote]
    shell.c:9: parse error before "num"
    [/code]
    Parse error..... means add a ";" sign (without the quotes) behind that no-make-sense-line-of-code -void sh(char *cmd) )

    Apparently you have a long way to go start by making the infamous Hello program
    + init main returns 0; (in ur case)

    But before you start asking yourself WTF are they talking about i suggest you search some tutorials....

    P.S: Sry if i was rude at any point but i understand your position completely, when i started coding it took me 4 months to find out how this thing actually works. That was because i didnt searched the net for tutorials and because i hadnt followed any programming clas, nor did i had a book about programming. But ill never forget when i made my first application that actually did something usefull and worked without bugs in it....


    BTW: Welcome to the board!!!

    And i just looked on the net and this seems pretty good... just went trough ex1 and only thing is they write main instead of int main check it out .
    2 late now going to bed
    Last edited by GanglyLamb; 06-12-2003 at 04:05 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  4. pointers
    By InvariantLoop in forum C Programming
    Replies: 13
    Last Post: 02-04-2005, 09:32 AM
  5. Struct *** initialization
    By Saravanan in forum C Programming
    Replies: 20
    Last Post: 10-09-2003, 12:04 PM