I'm trying to pass a structure array to a function so that the function uses a pointer to the array. everything works fine until I try to do what I was taught, which is trying to use the "->" operator. here's my sample code that works fine with no errors:
Code:
#include <stdio.h>
struct person {
char fname[50];
char mname[50];
char lname[50];
};
struct ssinfo {
char ssnum[10];
struct person name;
};
void printssinfo(struct ssinfo *peoples);
int main(void)
{
struct ssinfo people[5] =
{
{"123456789", {"Eric", "David", "Daly"} },
{"987654321", {"Ricky", "Alfred", "Andrews"} },
{"102938475", {"Isabel", "", "Loft"} },
{"019283746", {"Chris", "", "Yaeworth"} },
{"784632583", {"Jeffrey", "David", "Steinberg"} }
};
printssinfo(people);
puts("\n\nPress any key to continue...");
getch();
return 0;
}
void printssinfo(struct ssinfo *peoples)
{
int ctr;
for (ctr = 0; ctr < 5; ctr++)
{
printf("%s, %s ", peoples[ctr].name.lname, peoples[ctr].name.fname);
if (peoples[ctr].name.mname[0] != '\0')
{
printf("%c. ", peoples[ctr].name.mname[0]);
}
printf("-- %s\n", peoples[ctr].ssnum);
}
}
why does it work fine using "." but not using "->" like I thought I was supposed to be using?