I am trying to initialize an array of type struct within main() but compiler returns error field designator cannot initialize a non-struct, non-union type
My Code:
struct details{
const char *author;
const char *title;
};
int main()
{
const char *input = "Data Structures and Algorithm";
struct details a [] = {
.author = "Narsimha",
.title = input
};
printf("%s\n", a[0].author);
printf("%s\n", a[0].title);
return 0;
}
gcc inputs.c
inputs.c:16:9: error: field designator cannot initialize a non-struct, non-union type 'struct details []'
.author = "Narsimha",
^
inputs.c:17:9: error: field designator cannot initialize a non-struct, non-union type 'struct details []'
.title = input
^
2 errors generated.