command line arguments

This is a discussion on command line arguments within the C Programming forums, part of the General Programming Boards category; I have a prog that reads in a file, manipulates it, and writes it to another file my command line ...

  1. #1
    Unregistered
    Guest

    command line arguments

    I have a prog that reads in a file, manipulates it, and writes it to another file my command line details are
    prog input.txt output.txt -m -u

    my question is after i compile do i just type in prog input.txt output.txt -m -u or is there something else i need to do or a special way of compilling

  2. #2
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    You have to make the executable (prog.exe). What are the switches for? What shell are you using? Are they switches or does your program process them? As far as I can tell without seeing any code this much appears to look correct:

    prog input.txt output.txt

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Assuming you've written it correctly, yes, just invoke it as you've described:

    myproggie file1 file2 arg1 arg2

    Now, if you haven't written it correctly, this is how you do it:
    Code:
    int main ( int argc, char**argv )
    {
       /**
       *** Do stuff here.
       **/
       int x;
       for(x=0;x<argc;x++) puts( argv[x] );
       return 0;
    }
    Quzah.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Beginner Needs help in Dev-C++
    By Korrupt Lawz in forum C++ Programming
    Replies: 20
    Last Post: 09-28-2010, 02:17 AM
  2. GradeInfo
    By kirksson in forum C Programming
    Replies: 23
    Last Post: 07-16-2008, 04:27 PM
  3. command line arguments
    By vurentjie in forum C Programming
    Replies: 3
    Last Post: 06-22-2008, 07:46 AM
  4. NULL arguments in a shell program
    By gregulator in forum C Programming
    Replies: 4
    Last Post: 04-15-2004, 11:48 AM
  5. registry, services & command line arguments.. ?
    By BrianK in forum Windows Programming
    Replies: 3
    Last Post: 03-04-2003, 02:11 PM

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