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

int main() {

  char* attempt;
  char* password="buddy";

do
 {

  printf("Type a password:\n");
  scanf("%s", attempt);

if (attempt==password){

printf("You got it!\n");}
}

while (attempt!=password);
return 0;

}

2 Answers

1
nemequ On

You have to allocate space for the string… try char attempt[512];.

Also, attempt!=password doesn't do what you think… use strcmp().

0
yaho cho On

attempt==password is not working because these are different pointer value which have an address of memory.

Use strcmp function.

if (strcmp(attempt,password)==0){