UP | HOME
../../

C Language Main Method

  1. The C language main method can examine the contents of argv[*] before deciding what to do.
  2. int main(int argc, char * argv[]) {
        printf("argv[0]==%s\n", argv[0]);
        if (strcmp(argv[0], "name1"))
           doName1(argc, argv);
        else if (strcmp(argv[0], "name2"))
           doName2(argc, argv);
        doPrg(argc, argv);
    }
    
  3. Suppose the program is named prg located in the current directory.
  4. Suppose we established symlinks named name1 and name2.
  5. This program can be invoked through the shell using one of three names: ./prg, ./name1, and ./name2.
  6. busysbox uses this technique.

1 End


Copyright © 2017 www.wright.edu/~pmateti • 2017-09-29