vendredi 15 février 2019

using if statements with command line parameters in c

I am having trouble with getting my if statements to work with parameters from the command line. I get an error saying, 'comparison between pointer and integer ('char *' and 'int')' every time. Any help will be greatly appreciated. Here is the description for what I have to do:

This program will read a parameter from the command line and translate it to the name of the corresponding month. I.e. if you run the program with the following parameter:

It will print the following message:

The month is 'April'.

#include <stdio.h>

int main(int argc, char *argv[]) {
    if(argv[1] == 1){
        printf("You entered the number 1.");
    } else {
        printf("You entered a different number.");
    }

    return 0;
}

Aucun commentaire:

Enregistrer un commentaire