C program to print input longer than 10 characters The program will read the user's input, if it's longer or equal to 10 characters, it will print it.

It's pretty compact and works fine.

#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#define MAX_SIZE 1000

int main(void){
    char line[MAX_SIZE];
    int length; /*String length*/

    while((fgets(line, sizeof(line), stdin) != NULL)){
        line[length = (strlen(line)-1)] = '\0'; /*Remove the \n character*/
        if(length &gt;= 10){
            printf("%s\n", line);
        }
    }
    return 0;
}


Not looking for anything specific, method, style, etc..
The magic value 10 is embedded deep in the logic; I would make it an obvious constant (it might one day come from the command-line arguments).

Before overwriting the final \0 with NUL, you will probably want to check that it is actually \n.  If not, then you may have received the start of a line that's more than 1000 characters, and you'll want to print it and all the subsequent inputs until you do receive a \n (note that if you receive 1000 chars and then 5 chars, you can't ignore the 5-char input, because it's actually part of a 1005-char line).  Also, consider when an input line is read as two separate 6-character chunks - your code would discard both, instead of treating them as a single 12-char unit.

Overwriting the final \n with NUL seems to me pointless here, as you add one back on when writing it out.  It's probably better to keep the newline there, and increase your comparison size to take account of it.

Error checking - fgets() can fail, but you treat all failures as end-of-file.  Also, we don't normally write != NULL explicitly; all non-NULL values are true, so reduce the clutter.

The scope of length can be reduced, as it's not used outside the loop.  Except that I'm going to keep track of the length of lines that are split over more than one read, which moves it back again.

Minor style nit: I don't like writing the sizeof operator to look like a function.  It isn't a function, and I prefer it to be distinct.  I know there's a spectrum of opinion on that, so I won't push the point.

It gets surprisingly involved when you take into account partial reads and longer lines:

#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;

#define MAX_SIZE 1000

const int max_len = 10;

int main(void)
{
    char line[MAX_SIZE];
    int length = 0;
    int is_continuation = 0;

    while (fgets(line + length, (sizeof line) - length, stdin)) {
        length += strlen(line + length);
        /* length includes the final newline */
        if (is_continuation || length &gt;= max_len+1) {
            printf("%s", line);
            is_continuation = line[length-1] != '\n';
            length = 0;
        } else {
            is_continuation = line[length-1] != '\n';
            if (!is_continuation)
                /* reset for next read */
                length = 0;
        }
    }

    /* do we have any remaining input?  It may or may not end in newline */
    if (length) {
        if (is_continuation || length &gt;= max_len + (line[length-1] == '\n')) {
            printf("%s", line);
            length = 0;
            is_continuation = line[length-1] != '\n';
        }
    }

    if (feof(stdin))
        return EXIT_SUCCESS;

    perror("stdin");
    return EXIT_FAILURE;
}