I am having some issues with pointers (I am very new to coding). In main() I am trying to initialize my employee roster through InitWorkerArray
so I can then print it (that function is not included below), but whenever I try CodeBlocks just shuts down. I've looked up a lot of information on pointers, but few seem to deal with arrays/structs, so any help would be appreciated. I'm sure I have a lot of errors, unfortunately.
#include <stdio.h>
#include <stdlib.h>
typedef struct workerT_struct {
char *pName; //employee name
int maxName; //size, in chars, of the memory buffer to store emp name
char *pTitle; //employee title
int maxTitle; //size of the memory buffer created to store title
} workerT;
void initWorkerArray(workerT *pList, int siz);
void prntWorker(workerT *pList, int siz, int indx);
int main()
{
int maxRoster = 8;
workerT *pRoster;
pRoster = (workerT*)malloc(sizeof(workerT) * maxRoster);
pRoster = NULL;
initWorkerArray(pRoster, maxRoster);
return 0;
}
void initWorkerArray(workerT *pList, int siz) {
pList[0].maxName = 32;
pList[0].maxTitle = 50;
pList[0].pName = malloc(sizeof(char) * maxName);
pList[0].pTitle = malloc(sizeof(char) * maxTitle);
strcpy(pList[0].pName, "Buggy, Orson");
strcpy(pList[0].pTitle, "Director/President");
strcpy(pList[1].pName, "Czechs, Imelda");
strcpy(pList[1].pTitle, "Chief Financial Officer");
strcpy(pList[2].pName, "Hold, Levon");
strcpy(pList[2].pTitle, "Customer Service");
return;
}
void prntWorker(workerT *pList, int siz, int indx) {
int i = indx;
printf("%s, ", pList[i].pName);
printf("%s, ", pList[i].pTitle);
printf("\n\n");
return;
}