0

when I run with abc as the input argument nothing prints, why?

#include<stdio.h>

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

if (argv[1]=="abc")
{ 
printf("1");
}

}

2 Answers2

2

== does not compare strings, you need to use the strcmp function

necromancer
  • 23,916
  • 22
  • 68
  • 115
2

To compare strings use strcmp() as

if (strcmp(argv[1], "abc") == 0)
    printf("1");

The way your are checking using == will compare 2 char * pointers argv[1] and `"abc".

Rohan
  • 52,392
  • 12
  • 90
  • 87