• [^] # Re: Les arguments

    Posté par . En réponse au message Utiliser le terminal Linux pour compiler en C. Évalué à 3. Dernière modification le 04 juin 2013 à 15:27.

    http://crasseux.com/books/ctutorial/argc-and-argv.html

    argv[0] représente la chaine utilisée pour appeler le programme et non le programma appelant.

    As you can see, the first argument (argv[0]) is the name by which the program was called, in this case gcc. Thus, there will always be at least one argument to a program, and argc will always be at least 1.
    The following program accepts any number of command-line arguments and prints them out:
    #include <stdio.h>
    int main (int argc, char *argv[])
    {
     int count;
     printf ("This program was called with \"%s\".\n",argv[0]);
     if (argc > 1)
     {
     for (count = 1; count < argc; count++)
     {
     printf("argv[%d] = %s\n", count, argv[count]);
     }
     }
     else
     {
     printf("The command had no other arguments.\n");
     }
     return 0;
    }
    If you name your executable fubar, and call it with the command ./fubar a b c, it will print out the following text:
    This program was called with "./fubar".
    argv[1] = a
    argv[2] = b
    argv[3] = c