Thread: command line arguments

  1. #1

    command line arguments

    ok this deal with command line arguments is a bit weird and hard to understand.

    basically I got the following code that isn't working, it's giving a
    Segmentation Fault and I don't know why

      /* prints command line in reverse order */
      #include <stdio.h>
        main(int argc, char *argv[])
          int i;
         for( i=argc ; i > 0; i-- )
             printf("%s\n", argv[i]);
          return i;
    wouldn't i=argc in loop (argc -which is the total # of arguments on command line)? then decrement to 0???

  2. #2
    Registered User
    Join Date
    Sep 2001
    argc is the size of the array -- like all arrays, the last element is argc - 1.

    Change to i = argc -1 and it will work.

  3. #3

    Thumbs up WORKS LIKE A CHARM !!

    Thanks V. that worked beautifully.

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, 01:17 AM
  2. GradeInfo
    By kirksson in forum C Programming
    Replies: 23
    Last Post: 07-16-2008, 03:27 PM
  3. command line arguments
    By vurentjie in forum C Programming
    Replies: 3
    Last Post: 06-22-2008, 06:46 AM
  4. NULL arguments in a shell program
    By gregulator in forum C Programming
    Replies: 4
    Last Post: 04-15-2004, 10:48 AM
  5. registry, services & command line arguments.. ?
    By BrianK in forum Windows Programming
    Replies: 3
    Last Post: 03-04-2003, 02:11 PM