CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2002
    Posts
    9

    C code for printing command line argument

    In C, I'm trying to have it so that if i type ./a.out <filename> in the command line, it automatically prints out the filename i entered... i am unsure as to how to do this... can someone please point me to a place that has some example code?

    thanks

  2. #2
    Join Date
    Sep 2002
    Location
    Belarus - Tirol, Austria
    Posts
    647
    Base definition of main:
    int main( int argc, char *argv[])
    {
    };

    here argc - number of params passed to program

    so

    argv[0] - path of your program
    argv[1] - in your case, will be a file name U gave to program
    ./a.out file
    "UNIX is simple; it just takes a genius to understand its simplicity!"

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured