i use this code
in order to input to a char array in a row
but i need to input the length of the string i am about to enter

i have a char array of 40 cell
how to input to it in a row?
and how to tell where my input chars end in this array ?
Code:
    int index;
    char input[40];
    int i;
    int length=5;


 printf("enter string\n");
 for(index=0;index<length;index++){
   scanf("%c",&input[index]);
 }
 i=getchar();