Demo entry 2843002

check.c

   

Submitted by anonymous on Oct 16, 2015 at 19:49
Language: C. Code size: 895 Bytes.

#include <stdio.h>
#include <string.h>

int main(int argc, char** argv) {
    char buffer[256];
    char loop = 'y';
    int len;
    while (loop == 'y') {
        printf("Enter the passphrase: ");
        memset(buffer, 0, sizeof(buffer));
        fgets(buffer, sizeof(buffer), stdin);
        len = strlen(buffer);
        buffer[--len] = 0;
        if (strcmp(buffer, "fsociety") != 0) 
            puts("Sorry, wrong guess.");
        else {
            puts("Bonsoir Elliot!");
            break;
        }
        printf("Do you want to try again? (y or n): ");
        fflush(stdin);
        scanf("%c", &loop);
        fflush(stdin);
        if (loop == 'n') break;
        if (loop != 'y') {
            puts("Unknown command. Exiting..");
            return 0;
        }
    }
    puts("Thank you for playing!");
    getchar();
    return 0;
}
        

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).