Passing argc and argv from main to other functions

This is a discussion on Passing argc and argv from main to other functions within the C Programming forums, part of the General Programming Boards category; Currently, i'm stuck on this code: Code: #include <stdio.h> #include <stdlib.h> int test(int ArgNum, char *ArgList[]) { return 0; } ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,337
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 05: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

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