Quale sarebbe il problema? Limitare l'input ad una lunghezza arbitraria? Bloccare l'input utente al carattere i-esimo? Eliminare il carriage return?
Con qualche distinguo, per ottenere tutto ciò è necessario e sufficiente usare banalmente fgets().
#define MAX_SIZE 32
...
char name[MAX_SIZE];
...
fgets(name, MAX_SIZE, stdin);
{
char *p;
p = strchr(name, '\n');
if (NULL != p)
{
*p = '\0';
}
}
La fgets(), funzione inerentemente robusta, accetterà al massimo MAX_SIZE -1 caratteri dall'input e aggiungerà il necessario terminatore di stringa.