..C.. I am trying to figure out how to access my filled array which utilizes a struct with another function which I will use later for sorting, but I can't even print my function that filled the array in my main.
I have loaded the function inside main which works and printing inside the fillArray function works but I will need to access the array from outside the function later on for a bubble sort and a binary search.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define SIZE 100
typedef struct Person
{
char firstname[25];
char lastname[25];
} person;
person list [SIZE];
person loadPeople(char firstname[25],char lastname[25])
{
person p;
strcpy(p.firstname, firstname);
strcpy(p.lastname, lastname);
return p;
}
void fillArray()
{
list[0] = loadPeople("Bob","Baker");
list[1] = loadPeople("Bill","Johnson");
list[2] = loadPeople("John","Finmeister");
list[3] = loadPeople("Jennifer","Ratblaster");
list[4] = loadPeople("Shaun","Gares");
list[5] = loadPeople("Diggy","McDigMaster");
list[6] = loadPeople("Joanne","TheStore");
}
int main(int argc , char *argv[])
{
printf("First homie's name is: %s %s\n",list[0].firstname,list[0].lastname);
return 0;
}
I just want to print from main recalling from fillArray but right now it only prints:
First homie's name is:
thats it
fillArray()before trying to read data from the array.