C/C++ How to Get main Method Parameter


int main(int argn, char * argv[]) {
    if (argn == 1) {
        printf("Parameter at index 0 is %s\n", argv[0]);
        exit(0);//Exit without error
    }

    char strOne[1024];
    if (argn == 2) {
        strcpy(strOne, argv[1]);
        printf("Parameter at index 1 is %s\n", strOne);
        exit(1);//Exit with error
    }
}

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.