0

I am writing a program that takes two input parameters the first input parameter MUST be "-t", the second can be any number.

In order for the program to proceed, it must first check if the first parameter is "-t"

so for example, I would run it by typing "./a.out -t 45"

I tried to do this using the following:

int main(int argc, char *argv[]){
    char *par ;
    par = argv[1];

    if(par == "-t"){
         printf("The parameter is: %s \n, The program will proceed" , par);
    } else {
         printf("Incorrect input \n");
         exit(1);   
    }

    // continue program
}

However I always get "Incorrect input no matter what, I'm not sure what I'm doing wrong. The variable "par" is a character array, and the parameter that I'm comparing it to is a character array so shouldn't the first part of the if statement execute instead of the else?

I looked here: C - reading command line parameters

but it wasn't much help. I can print the parameter just fine, I just can't compare it.

Hitomi86
  • 45
  • 7

0 Answers0