Linked Questions

Popular Questions

I try to implement a Funktion in C which is work with the char *argv[] and with switch-case in the Main Method.

I found a Simular Question but the answer is not helping me out. The answer of plinth is simular what i need, but this is not working for my code. I get of the answer from plinth this error:

UserInput.c: In function ‘keyfromstring’: UserInput.c:126:22: error: incompatible types when initializing type ‘t_symstruct * {aka struct <anonymous> *}’ using type ‘t_symstruct {aka struct <anonymous>}’ t_symstruct *sym = lookuptable[i];

#include <stdio.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h> // isdigit



int main(int argc, char *argv[]) {

    if (argc == 1)

        {
        printf("- no arg \n\n");

        }


    for (int i = 1; i < argc; i++) {
        int j = i +1;

        if (argv[i][0] == '-') {
            switch (argv[i][1]) {

            case 'h':

                if(argv[j] && strcmp(argv[j], "JsonFile") == 0){
                    printf("\nhelp you with %s\n\n", argv[j]);
                    break;
                }
                printf("\nhelp you with %s\n\n", argv[i]);
                break;

            case 'configFile':
                printf("ConfigFile!!!, %s \n\n", argv[i] );
                break;

            default:
                printf("Unknown option %s\n", argv[i]);
            }
        }
    }

}

I exepct if i compile and start my Programm with ./a.out configFile that they print me ConfigFile!!!.

Related Questions