I tried to use a variable set at runtime to specify the size of a character array,
#include<stdio.h>
int main(void)
{
int n;
printf("ENTER THE NUMBER OF Characters IN THE STRING:\n");
scanf("%d",&n);
char string[n];
printf("Enter the string:\n");
scanf("%s",string);
printf("\nTHE STRING IS:\n");
printf("%s\n",string);
return 0;
}
I'm not able to understand the following output,
ENTER THE NUMBER OF Characters IN THE STRING:
2
Enter the string:
abcdefghijk
THE STRING IS:
abcdefghijk
Even after specifying the number of characters in the string as 2, why is the whole of the string that is entered being displayed?