Having this piece of code:

```
int main(void)
{
    char str[4];

    do
    {
        if (fgets(str,sizeof(str),stdin) == NULL)
            break;
        printf("\n %s \n", str);
    }while (strncmp(str,"q\n",sizeof("q\n")));

    return 0;
}

```

if i type more than 4 characters, then two lines are displayed. if i type 123456 and then press enter, does input store ['1','2','\n','\0'] or ['1','2','3','\0']? hen the second time printf is reached if i only press enter key one time?. How i can avoid this behaviour? I would like type 123456 and then get:

```
1234 

```