I am having trouble getting my nested structs to print. I want the phone struct to print, but I'm not quite sure how to format it. I'm thinking it's what I did when I actually created the struct, but I could be wrong. Another problem I'm having is when I'm actually calling the print functions. More specifically, the pointer print function prEmps2. I just don't know how to get it to call properly. I've highlighted the areas that I've been struggling with.
Code:
#include <stdio.h>
#include <stdlib.h>
#define MAXNAME 40
#define MAXDIGITS 27
struct phone
{
char areacode[MAXDIGITS];
char localprefix[MAXDIGITS];
char finalfour[MAXDIGITS];
} ;
struct employee
{
long number;
char name[MAXNAME];
struct phone areacode, localprefix, finalfour;
int age;
} ;
int main(void)
{
void printEmps(struct employee table[], int);
void peEmps2(struct employee *ptr, int);
struct employee emptab[] =
{
{1986, "mario, super", "758", "748", "2634", 64},
{2012, "man, super", "423", "436", "2353", 98},
};
printEmps(emptab,sizeof(emptab)/sizeof(emptab[0]));
prEmps2()
system("PAUSE");
return 0;
}
void printEmps(struct employee table[], int n)
{
int i;
for (i = 0; i < n; i++)
printf("Employee Number: %s\n Name: %s\n Phone: (%s)%s-%s\n Age: %i\n",
table[i].number, table[i].name, table[i].phone areacode,
table[i].phone localprefix, table[i].phone finalfour, table[i].age);
}
void prEmps2(struct employee *ptr, int n)
{
struct employee *endptr = ptr + n;
for (; ptr < endptr; ptr++)
printf("Name: %s\n", ptr->name);
}