0

When i try to run this code:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char *argv[]){
   int i;
   for(i = 0; i < argc; i++){
      printf("argv[%d]: %s\n", i, argv[i]);
   }
   for(i = 1; i < argc; i++){
      if(argv[i] == "-h"){
         printf("You got helped\n");
      }else{
         printf("Failure!\n");
      }
   }
}

It always returns "Failure!". I tried to get it to return a help message aka "You got helped" when i run it with the "-h" flag, but it's not working. Any help?

RadoslavL
  • 21
  • 7
  • 1
    Does this answer your question? [How do I properly compare strings in C?](https://stackoverflow.com/questions/8004237/how-do-i-properly-compare-strings-in-c) – Passerby Dec 02 '21 at 07:41
  • @Passerby Thanks that fixed it. Any idea on why my version does not work? – RadoslavL Dec 02 '21 at 08:23

0 Answers0