Thread: Passing argc and argv from main to other functions

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    6

    Passing argc and argv from main to other functions

    Currently, i'm stuck on this code:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int test(int ArgNum, char *ArgList[]) {
      return 0;
    }
    int main(int argc, char *argv[]) {
      test(argc, &argv[]);
      return 1;
    }
    But it doesn't even get through compiling:

    Code:
    EmbedTestFunc.obj : error LNK2005: _main already defined in EmbedTest.obj
    C:\Documents and Settings\...\Visual Studio 2005\Projects\EmbedTest\Debug\EmbedTest.exe : fatal error LNK1169: one or more 
    multiply defined symbols found
    As far as I've seen examples, this should work, but it doesn't, so something's missing ... thanks.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > EmbedTestFunc.obj : error LNK2005: _main already defined in EmbedTest.obj
    You have two mains, rename one of them to be something else.

    > test(argc, &argv[]);
    This would simply be
    test(argc, argv);
    Both parameters are the same type, so it's simply the name of the variable.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Using argc and argv data
    By Rad_Turnip in forum C Programming
    Replies: 4
    Last Post: 03-31-2006, 06:09 AM
  2. Converting a argc / argv construct into a va_list
    By chambece in forum C Programming
    Replies: 6
    Last Post: 07-03-2005, 04:47 PM
  3. passing params to main()
    By mike11 in forum C++ Programming
    Replies: 14
    Last Post: 06-21-2005, 12:36 PM
  4. argc & argv
    By miryellis in forum C Programming
    Replies: 11
    Last Post: 09-19-2004, 11:59 PM
  5. how do i? re: argc - argv
    By luigi40 in forum C Programming
    Replies: 2
    Last Post: 06-11-2004, 10:17 AM