-1
#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;

}
Bruno
  • 1
  • 3

2 Answers2

1

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

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

nemequ
  • 16,623
  • 1
  • 43
  • 62
0

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){
yaho cho
  • 1,779
  • 1
  • 7
  • 19