Thread: trouble passing parameter to function

  1. #1
    Registered User
    Join Date
    Dec 2012
    Posts
    1

    trouble passing parameter to function

    I'm having some difficulty compiling the following code. When I run

    Code:
     void list_dir (char * dir_name)
    {
        DIR * d;
        d = opendir (dir_name);
    .....
    }
    
    int main (int argc, char *argv[])
    {     
       list_dir (argv[1]);
        return 0;
    }

    my program compiles without issue, but when I try to pass a second parameter to the function of either argv[2] or *argv, the compiler is telling me too few parameters to function or expecting * when parameter is **, an example is....

    Code:
    void
    list_dir (char * dir_name, char * newz)
    {
        DIR * d;
      d = opendir (dir_name);
    .....
    }
    
    int main (int argc, char *argv[])
    {
        list_dir (argv[1], argv[2]);
        return 0;
    }

    Any suggestions on why the compiler doesn't accept how the second argument, argv[2], is being passed. Thanks!

  2. #2
    Registered User
    Join Date
    Mar 2011
    Posts
    546
    looks correct to me. can you post the exact error message and the exact code rather than an excerpt. try to boil it down to a very simple example.

  3. #3
    Registered User
    Join Date
    May 2012
    Location
    Brazil
    Posts
    58
    Is there a function prototype for list_dir before this?
    If so maybe it's different from the function definition.

  4. #4
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Indeed, the important bit is in precisely what is different between the example you post here and the real code.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. passing a file as a function parameter
    By philgrek in forum C Programming
    Replies: 1
    Last Post: 03-06-2011, 01:13 PM
  2. Passing an array to a function as a parameter
    By boxden in forum C Programming
    Replies: 1
    Last Post: 03-13-2010, 09:35 AM
  3. Problems passing parameter to function
    By HAssan in forum C Programming
    Replies: 5
    Last Post: 10-21-2008, 02:26 PM
  4. Passing array of struct as a function parameter
    By desmond5 in forum C Programming
    Replies: 5
    Last Post: 12-04-2007, 11:32 AM
  5. passing a callback as function parameter
    By Rune Hunter in forum C++ Programming
    Replies: 4
    Last Post: 10-29-2005, 11:44 AM