fgets
public c v1 · immutable#include <stdio.h>#include <stdlib.h>#include <string.h>int main(){ char foo[5]; char c; if(fgets(foo, 5, stdin) != NULL) { if(strchr(foo, '\n') == NULL) { do c = fgetc(stdin); while(c != EOF && c != '\n'); } else foo[strlen(foo) - 1] = '\0'; } puts(foo); return 0;}