I want to store unknown string like if I want to store name of any person
Here is my attempt
error: array size missing in 'Name'
char Name [];
warning: format '%c' expects argument of type 'int', but argument 2 has type 'char *'
printf ("%c", &Name);
warning: unused variable 'i' [-Wunused-variable]
int i, size;
Edit : If the size of the array is unknown, is it necessary to allocate the dynamic memory?
Here is my attempt
C:
#include<stdio.h>
int main(void)
{
int i, size;
char Name [];
printf("Enter Size of Name \n");
scanf("%d",&size);
printf(" Size of Name : %d \n", size);
for (int i = 0; i < size; i++)
{
scanf ("%c", &Name[i]);
printf ("%c", &Name[i]);
}
return 0;
}
char Name [];
warning: format '%c' expects argument of type 'int', but argument 2 has type 'char *'
printf ("%c", &Name);
warning: unused variable 'i' [-Wunused-variable]
int i, size;
Edit : If the size of the array is unknown, is it necessary to allocate the dynamic memory?