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

bool scan(FILE *stream)
{
    int c;
    state_A:
        c = getc(stream);
        if (c == 'a') goto state_F;
        else goto state_err;

    state_F:
        c = getc(stream);
        if (c == 'a') goto state_C;
        if (c == 'c') goto state_F;
        if (c == EOF) goto state_succ;
        else goto state_err;

    state_C:
        c = getc(stream);
        if (c == 'b') goto state_F;
        else goto state_err;


    state_succ: return true;
    state_err: return false; 
}

int main()
{
    printf("Please give your input, and end with ^D (twice?): ");
    if (scan(stdin))
    {
        printf("\nAccepted!\n");
    } else {
        printf("\nRejected.\n");
    }
}
