Thread: give arguments

  1. #1
    Registered User
    Join Date
    Jan 2003
    Posts
    45

    give arguments

    It is very nice that I can use the arguments passed to a program with the
    Code:
    int main(int ArgC, char* Argv[])
    but my question is how CAN i pass an argument to a program?
    (ok its newbie stuff, but I just dont know it)

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Start the program from the console using:

    MyProg 45 2 987

    or something
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Oh, and another useful aspect of main arguments: If you associate (sp?) a file extension with your program, then double click on that file, your program will load with the path + filename of that file as an argument.
    This is really useful, since you can tell your program to automatically load this file.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  4. #4
    Registered User
    Join Date
    Mar 2003
    Location
    UK
    Posts
    170
    Small example, note that the first arg is the programs name.
    Code:
    #include <stdio.h>
    
    int main(int ArgC, char* Argv[])
    {
    	for(int i=0; i<	ArgC; i++)
    		printf("Argv %d = %s\n", i, Argv[i]);
    	return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Variable Arguments through Command Line
    By zombiezparadize in forum C Programming
    Replies: 5
    Last Post: 05-06-2008, 07:35 AM
  2. CreateProcess with arguments
    By Niara in forum Windows Programming
    Replies: 14
    Last Post: 09-08-2007, 05:41 AM
  3. need help with command line arguments
    By cyber_tech in forum C Programming
    Replies: 13
    Last Post: 08-06-2007, 07:45 AM
  4. command line arguments
    By belusha in forum C Programming
    Replies: 4
    Last Post: 01-27-2003, 09:35 PM
  5. (Variable Arguments,...)
    By Sebastiani in forum C Programming
    Replies: 3
    Last Post: 09-07-2001, 10:44 AM