0

i have entered 'pass1' as a value to 'str' so that 'if' construct would work but still its not working. code is down below:

code:

#include <stdio.h>
#include <string.h>
#define ab "pass1"

int main() {
  char pass[8];
  char str[8];
  printf("Enter a string :");
  gets(str);
  strcpy(pass, str);

  printf("your string is %s ", str);

  if (pass == ab) {
    printf("la swagat cha!");
  }
}
Bill Lynch
  • 80,138
  • 16
  • 128
  • 173
Abhishek
  • 546
  • 5
  • 13
  • 2
    You can't compare strings with `==`. You need a function like `strcmp()`. – alex01011 Aug 18 '21 at 15:20
  • 2
    Aside, [Why is the gets function so dangerous that it should not be used?](https://stackoverflow.com/questions/1694036/why-is-the-gets-function-so-dangerous-that-it-should-not-be-used). – alex01011 Aug 18 '21 at 15:21

0 Answers0