Read line from stdin until EOF and print the text after test for first character
<p><strike>I wanr interactive</strike>(I want to) read a line from standard input until EOF but after each line I want to print if the line first character is <code>'+'</code> then print <code>"OK"</code> else print <code>"NOT OK"</code>.  I tried this code but this prints <code>"NOT OK"</code> even if the line I input has a first character equal to <code>'+'</code>.</p>

<pre><code>int main()
{
    #define BUF_SIZE 1024
    char buffer[BUF_SIZE];
    size_t contentSize = 1;
    /* Preallocate space.  We could just allocate one char here,
    but that wouldn't be efficient. */
    char *content = malloc(sizeof(char) * BUF_SIZE);
    if(content == NULL)
    {
        perror("Failed to allocate content");
        exit(1);
    }
    content[0] = '\0'; // make null-terminated
    while(fgets(buffer, BUF_SIZE, stdin))
    {
        char *old = content;
        contentSize += strlen(buffer);
        content = realloc(content, contentSize);
        if(content == NULL)
        {
            perror("Failed to reallocate content");
            free(old);
            exit(2);
        }
        strcat(content, buffer);
        if (content[0]== '+')  {
            printf("OK\n");
        } else {
            printf("NOT OK\n");
        }
    }

    if(ferror(stdin))
    {
        free(content);
        perror("Error reading from stdin.");
        exit(3);
    }
}
</code></pre>