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

static void check(const char *label, int ok)
{
    puts(label);
    puts(ok ? "  OK" : "  FAIL");
}

int main(void)
{
    char buf[32];

    /* strlen */
    check("strlen(\"\") == 0",         strlen("") == 0);
    check("strlen(\"hello\") == 5",    strlen("hello") == 5);

    /* strcpy + strlen */
    strcpy(buf, "Sprinter");
    check("strcpy + strlen == 8",      strlen(buf) == 8);

    /* strcmp */
    check("strcmp(\"a\",\"a\") == 0",  strcmp("a", "a") == 0);
    check("strcmp(\"a\",\"b\") < 0",   strcmp("a", "b") < 0);
    check("strcmp(\"b\",\"a\") > 0",   strcmp("b", "a") > 0);
    check("strcmp(buf,\"Sprinter\")",  strcmp(buf, "Sprinter") == 0);

    /* strcat */
    strcpy(buf, "Hello ");
    strcat(buf, "Sprinter!");
    check("strcat -> \"Hello Sprinter!\"", strcmp(buf, "Hello Sprinter!") == 0);

    /* memcpy */
    memset(buf, 'X', 16);
    memcpy(buf + 4, "ABCD", 4);
    buf[16] = 0;
    check("memset+memcpy -> \"XXXXABCDXXXXXXXX\"",
          strcmp(buf, "XXXXABCDXXXXXXXX") == 0);

    /* memset */
    memset(buf, 'q', 5);
    buf[5] = 0;
    check("memset(buf,'q',5) -> \"qqqqq\"", strcmp(buf, "qqqqq") == 0);

    /* memcmp */
    check("memcmp equal",   memcmp("abcd", "abcd", 4) == 0);
    check("memcmp diff",    memcmp("abcd", "abxd", 4) != 0);

    puts("");
    puts("All checks done.  Press any key to exit.");
    (void)getchar();
    return 0;
}
