Below is the code that works properly fine and shows the correct output.
But it highlights an error in the line char name[n]
, But why?
- I have already declared
n
and taken its input.
Then, I declare the array name[n]
which is highlighting n
under the char name[n]
.
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
int main()
{
int n;
printf("\n Enter the value of n - ");
scanf("%d",&n);
char name[n]; // <--------
for(int i=0 ; i<n ; i++)
{
name[i] = getch();
printf("*");
}
printf("\n");
for(int i=0 ; i<n ; i++)
{
printf("%c",name[i]);
}
getch();
}