command line arguements

This is a discussion on command line arguements within the C Programming forums, part of the General Programming Boards category; this sounds really stupid but looked through my notes several times and cannot find what command line arguements are. could ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    3

    command line arguements

    this sounds really stupid but looked through my notes several times and cannot find what command line arguements are. could someone give me an example.PLEASE.

  2. #2
    Registered User hk_mp5kpdw's Avatar
    Join Date
    Jan 2002
    Location
    Northern Virginia/Washington DC Metropolitan Area
    Posts
    3,672
    Command-line arguments are arguments(parameters) passed into the program when it is run from the command prompt (or passed to the program when a file is dragged and dropped onto an executable in Windows for example).

    Let's say you have a program called test.exe and you want to run it with some command-line arguments. At the command prompt you could do something like:

    test foo.txt bar.txt

    ... where foo.txt and bar.txt are the two command-line arguments passed into the program.
    I used to be an adventurer like you... then I took an arrow to the knee.

  3. #3
    Registered User
    Join Date
    Feb 2005
    Posts
    12
    Provided you're in the correct directory where your exe is located. So adding onto simplification where hk_mp5kpdw left, (for Windows)
    say your exe named test.exe is stored in C-drive and screamer folder. Then you first go to the command-prompt(some still call it DOS prompt) and then go to the c:\screamer folder and then do what mp5kpdw suggested.

  4. #4
    ---
    Join Date
    May 2004
    Posts
    1,379
    Incase you knew that and you actually needed a programming example, here it is:
    Code:
    #include <stdio.h>
    
    int main(int argc, char* argv[]){
      /* If arguments have been passed */
      if (argc > 0){
        /* Prints 1st argument in argv[1] (argv[0] is the name of the .exe file) */
        printf("Hello, %s\n",argv[1]);
      }
      else{
        /* If no arguments were passed... */
        printf("Anybody out there?\n");
      }  
      return 0;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Command line arguements in functions.
    By SlyMaelstrom in forum C++ Programming
    Replies: 4
    Last Post: 10-30-2005, 06:41 AM
  2. Comparing command line arguements to a string.
    By SlyMaelstrom in forum C++ Programming
    Replies: 14
    Last Post: 10-30-2005, 03:56 AM
  3. Arguements for gnome?
    By mart_man00 in forum Tech Board
    Replies: 12
    Last Post: 07-30-2003, 04:46 PM
  4. Command Line Arguements
    By scaven in forum C Programming
    Replies: 2
    Last Post: 04-13-2003, 05:36 PM
  5. Working With Command Line Arguements
    By mart_man00 in forum C Programming
    Replies: 4
    Last Post: 08-03-2002, 04:31 PM

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