+ 1

This program is giving an error that name is outside aggregate initializer so how can we remove it?

#include <stdio.h> struct student { int age; int grade; char name[40]; }; int main() { struct student s1 = { .grade = 9, .age = 19, .name = "John Birghimer"}; printf("Name: %s, Age: %d, Grade: %d\n", s1.name, s1.age, s1.grade); return 0; }

29th May 2020, 9:34 AM
Saurabh Yadav
Saurabh Yadav - avatar
3 Réponses
+ 2
Now I understand that you are getting a C++ compiler error on C code due to differences with structs between C and C++. Is your intention to convert the C code to run as a C++ program? If so, then I should defer to others here who have more DEV C++ experience. In the meantime, I will have to study and learn about this, myself.
29th May 2020, 10:51 AM
Brian
Brian - avatar
+ 1
The program worked perfectly for me when using the C compiler. Were you trying to compile it under C# (noting the c#struct keyword tag)?
29th May 2020, 9:54 AM
Brian
Brian - avatar
+ 1
I am talking about dev c compiler, in dev c this program is not working
29th May 2020, 10:03 AM
Saurabh Yadav
Saurabh Yadav - avatar