Why do I get Segmentation fault here? I'm very new to C and it's really hard for me. I googled much and found out that it have to be working normally.
#include <stdio.h>
struct school
{
int schoolNum;
int year;
int gradNum;
int univNum;
};
int main()
{
struct school schools[5] = {
114, 2020, 470, 300,
86, 2019, 545, 450,
231, 2020, 340, 320,
113, 2020, 435, 395,
55, 2019, 395, 380
};
printf('%d\n', schools[0].gradNum);
return 0;
}
"instead of'for string literals.printfcall are wrong. use double quotes for your format string. You should get a compiler warnings about the problem. (Enable all warnings.){ ... }in your initializer array of structures.