Hiya, I've been trying to allocate memory and put a single letter in an array within a struct that I know can actually fit it in. At the end of the day it just gives me a Segmentation Error and I'm back to wondering what I'm doing wrong.
Here's all the code.
int loadData(PMSType* pms, char* programFile, char* courseFile)
char input[PROG_ID_LEN + 1] = "P0001";
printf("Debug: Attempting to allocate memory");
if((prog =(ProgramType *) malloc(sizeof(ProgramType)) == NULL))
printf("Error: Could not allocate memory");
printf("Debug: Attempting to put p in progID");
prog->progID = 'p';
prog->progID = input;
typedef struct program
char progID[PROG_ID_LEN + 1]; /* Unique ID for a program */
char progTitle[MAX_TITLE_LEN + 1];
char progMajor[MAX_TITLE_LEN + 1];
char progCode[PROG_CODE_LEN + 1];
char progType[PROG_TYPE_LEN]; /* Undergrade(UG) or Postgrad (PG) */
char progMode[MODE_LEN]; /* Full-time (FT) or Part-time (PT) */
typedef struct pms
Also, it has told me that I have to initialise the system to a safe empty place... and I'm wondering if this is what I am supposed to put.
int systemInit(PMSType* pms)
pms = (PMSType *) malloc(sizeof(*pms));
if(pms == NULL)
printf("Error: Couldn't Allocate
Of course any help would be fantastic and if there's anything you need extra just ask.