I want to create an empty string with fixed length lets say 100 and then enter user input for that string , For some reason when I try to scan the string the code isnt showing me all the leading empty spaces after the user input . If my empty string is of length 20 and input is 5 character then the count should be 20 . Am I missing something very basic here or the compiler truncates the empty spaces no matter what ?
int main ()
{
int count=0;
char word[20];
printf("Please enter a sting: ");
scanf("%s", word);
while (word[count]!= '\0' )
{
printf ("%c",word[count]) ;
count++;
}
printf ("\nCharacter count :%i\n", count);
}
The output is :
Please enter a sting: Words
Words
Character count :5
Press any key to continue.