Not sure what is wrong here, I can't seem to compile. I am trying to pass the structure into the function to just print the list. I was asked to use "pass by value" instead of structure. Help is much appreciated, I am new to this and just read the chapter...
Also, is my structure initialization correct? Should I initialize it outside of the main function?
Code:
#include <stdio.h>
#include <string.h>
#define MAX 61
#define SIZE 5
struct name {
char fname[MAX];
char middle[MAX];
char lname[MAX];
};
struct sin {
int snumber;
struct name info;
};
void printNames(struct sin * temp[]);
int main(void)
{
int i = 0;
struct sin * ptrData;
struct sin data[SIZE] = {
{302039823, {"Flossie", "Marie", "Dribble"}},
{123456789, {"DeMar", "Test", "DeRozan"}},
{987654321, {"John", "", "Doe"}},
{736491092, {"Jane", "Cherry", "Dairy"}},
{282398624, {"Andrea", "James", "Bargnani"}}
};
//for (i = 0; i < SIZE; i++)
// ptrData[i] = &data[i];
ptrData = &data;
printNames(ptrData);
return 0;
}
void printNames(struct sin * temp[])
{
int i = 0;
for(i = 0; i < SIZE; i++)
{
if(temp[i]->info.middle[0] != '\0')
{
printf("%s, %s %c. -- %d\n", temp[i]->info.lname, temp[i]->info.fname, temp[i]->info.middle[0], temp[i]->snumber);
}
else
{
printf("%s, %s %*-- %d\n", temp[i]->info.lname, temp[i]->info.fname, temp[i]->info.middle[0], temp[i]->snumber);
}
}
}