I'm genuinly confused as to why i am having this error. My code compiles fine but i would prefer to have 0 warnings. After searching stackoverflow for a bit no one had the same structure type that i was using. Below is a snippit of my code (these are made up names)
if it helps my MAXCONTACTS is set to 5
struct Contact conNum[MAXCONTACTS] = { { {"Rick", { '\0' }, "Grimes" },
{11, "Trailer Park", 0, "A7A 2J2", "King City" },
{"4161112222", "4162223333", "4163334444" } },
{
{"Maggie", "R.", "Greene" },
{55, "Hightop House", 0, "A9A 3K3", "Bolton" },
{"9051112222", "9052223333", "9053334444" } },
{
{"Morgan", "A.", "Jones" },
{77, "Cottage Lane", 0, "C7C 9Q9", "Peterborough"},
{"7051112222", "7052223333", "7053334444" } },
{
{"Sasha", {'\0'}, "Williams" },
{55, "Hightop House", 0, "A9A 3K3", "Bolton"},
{"9052223333", "9052223333", "9054445555" } },
};
edit: here is my structure declaration
// Structure type Name declaration
struct Name {
char firstName[31];
char middleInitial[7];
char lastName[36];
};
struct Address {
int streetNumber;
int apartmentNumber;
char street[41];
char postalCode[8];
char city[41];
};
struct Numbers {
char cell[11];
char home[11];
char business[11];
};
struct Contact {
struct Name name;
struct Address address;
struct ``Numbers numbers;
};
Your struct Address contains two int fields followed by two char arrays:
struct Address {
int streetNumber;
int apartmentNumber;
char street[41];
char postalCode[8];
char city[41];
};
but you don't initialize them in that order:
{11, "Trailer Park", 0, "A7A 2J2", "King City" },
Unless you use named initializers, fields must be specified in order. Put the street number first, then the apartment number, then the street:
{11, 0, "Trailer Park", "A7A 2J2", "King City" },
Do the same with the other three.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With