Q:

argc/argv in c linked list or binary tree

So I am trying to make a linked list/binary tree and:
The user should be able to choose the data structure directly from the command line when it starts the program. This should use the argc or argv arguments to main()
how would I do this? I don’t get it why not just use switch case statement asking the student.
     option 1: linked list 

     option 2: binary tree?

we didn’t really cover argc argv properly can anyone help?
Apparently its a duplicate ... hmm.. well i am asking specically about binary tree/linked list how would the user tell it to choose which data structure? 

A:

Experiment with the following skeleton program, and find out.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
    if (argc != 2) {
        fprintf(stderr, "Usage: %s COMMAND\n", argv[0]);
        return EXIT_FAILURE;
    }

    if (!strcmp(argv[1], "foo")) {
        printf("Doing foo.\n");

    } else
    if (!strcmp(argv[1], "bar")) {
        printf("Doing bar.\n");

    } else {
        fprintf(stderr, "Unknown command line parameter '%s'.\n", argv[1]);
        return EXIT_FAILURE;
    }

    return EXIT_SUCCESS;
}

The most common way to inform the utility user as to what to do, is to run the utility without parameters, or with -h or --help as the only parameter. (Windows command-line utilities might use /? or similar.)
Let's say the user can run the compiled program, program in the following ways:
./program list
./program tree
./program -h
./program --help
./program

where the first form tells the program to use a linked list; the second form tells the program to use a tree; and the other forms just output usage, information on how to call the program:
Usage: ./program [ -h | --help ]
       ./program MODE

Where MODE is one of:
    list    Linked-list mode
    tree    Tree mode

Further details on what the program actually does...

You achieve this with very little code:
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

enum {
    NO_MODE = 0,
    LIST_MODE,
    TREE_MODE
};

int main(int argc, char *argv[])
{
    int mode = NO_MODE;

    if (argc != 2 || !strcmp(argv[1], "-h") || !strcmp(argv[1], "--help")) {
        printf("Usage: %s [ -h | --help ]\n", argv[0]);
        printf("       %s MODE\n", argv[0]);
        printf("\n");
        printf("Where MODE is one of\n");
        printf("    list    for linked list mode\n");
        printf("    tree    for tree mode\n");
        printf("\n");
        printf("Further details on what the program actually does...\n");
        printf("\n");
        return EXIT_SUCCESS;
    }

    if (!strcmp(argv[1], "list"))
        mode = LIST_MODE;
    else
    if (!strcmp(argv[1], "tree"))
        mode = TREE_MODE;
    else {
        fprintf(stderr, "%s: Unknown MODE.\n", argv[1]);
        return EXIT_FAILURE;
    }

    /* mode == LIST_MODE or TREE_MODE here,
       depending on the first command line parameter.
    */

    return EXIT_SUCCESS;
}

Note that || operator is short-circuited in C: if the left side is false, the right side is not evaluated at all. So, above, the first strcmp() check is only done when argv == 2, and the second when argv == 2 and the first strcmp() returned nonzero (no match).
In other words, the body of the usage section is only run when argv != 2 (there is less than two, or more than two command line items, counting the program name as one); or if the sole command-line parameter matches either -h or --help.
! is the not operator in C. !x evaluates to 1 if and only if x is zero or NULL; and to 0 otherwise.
(You can confuse people by using !!x. It evaluates to zero if x is zero, and to one if x is not zero. Which is logical. It's often called the not-not operation.)
The enum is just there to remind you that magic constants are bad; it is better to use either enums, or preprocessor macros (#define NO_MODE 0 and so on). It would be terribly easy to use 1 in one place to indicate tree mode, and 2 in another; such bugs are horrible to debug, needs way too much concentration from the human reading the code, to find such bugs. So don't use magic constants, use enums or macros instead.
Above, I decided that NO_MODE has value zero, and let the compiler assign (increasing) values to LIST_MODE and TREE_MODE; consider them compile-time integer constants. (Meaning, you can use them in case labels in a switch statement.)
Because strcmp() returns zero if the two strings match, !strcmp(argv[1], "baz")) is true (nonzero) if and only if argv[1] contains string baz. You see it all the time in real-world code when strings are compared.
If you look at my answers here, you'll very often see an if (argc ...) "usage" block in my example code. This is because even I myself will forget, often within days, exactly what the purpose of the program is. I typically have several dozen example programs on my machines I've written, and rather than looking at the sources to see if something jogs my memory, I simply run the example snippets without command-line parameters (or actually, with -h parameter, since some are filters), to see what they do. It's faster, less reading, and I'll find the relevant snippet faster.
In summary, write an usage output block in all your programs, especially when it is just a test program you won't publish anywhere. They are useful, especially when you have a library full of them, of various code snippets (each in their own directory; I use a four-digit number and a short descriptive name) that implement interesting or useful things. It saves time and effort in the long run, and anything that lets me be efficient and lazy is good in my book.

