Change the array size to a constant value.
Set the constant to allow only 30 characters input.
use #define to create constant
#include <stdio.h> #define INPUT_SIZE 30/*from ww w .ja va2s . c om*/ int main() { char name[INPUT_SIZE]; printf("Who are you? "); fgets(name,INPUT_SIZE,stdin); printf("Glad to meet you, %s.\n",name); return(0); }