0

I am trying to set up a c capture the flag challenge but I cannot get the if statement to work.

I have a text file with the following line in it:

flag{alm0st_th3r3}

This checks against my character phrase which is the same so should print out the answer and if not print out wrong.

I have tried it a number of ways and can't see where I am going wrong. The printf(flagText) and printf(phrase) just confirm that both are the same.

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

int main()
{
    FILE *flag;
    flag = fopen("flag.txt", "r");
    if (flag == NULL)
    {
    puts("Error: Opening file: Maybe you are in the wrong Zm9sZGVyIG9yIGRpcmVjdG9yeSAtIHRoZXJlIGFyZSAyMCBhZnRlciBhbGwh ?");
    return 1;
    }

    char flagText[100];
    fgets(flagText, 100,flag);
    fclose(flag);
    printf(flagText);
    char phrase[100] = "flag{alm0st_th3r3}";
    printf(phrase);
    printf("\n");

    if (flagText == phrase )
    {
        printf("9mLf%BkqX6@:Cp5FC/!%D)5O@Dbkc");
        return 0;
    }
    else
    {
        printf("Sorry - wrong!!");
        return 1;
    }

}
John Kugelman
  • 349,597
  • 67
  • 533
  • 578
Kartibok
  • 65
  • 7
  • Note that error messages should be printed to `stderr`, not `stdout`, and you should add a newline to the end of output messages. Your `printf()` statements are missing that — the `puts()` call adds a newline — but you'll need to do that yourself if you use `fputs("…\n", stderr)` to report the error. – Jonathan Leffler Jun 19 '21 at 13:56
  • Jonathan, much appreciated. – Kartibok Jun 20 '21 at 05:40

0 Answers0