S
Simon Mansfield
Hey guys, im trying to assign a read-in string to a string in an array
(Right at the bottom of the post). However the program crashes when it gets
to this line.. Obviously it's somthing to do with the way i am accessing the
array or writing to it.. But im not exactly sure what.. ??
I've given all the code you should need to understand the problem, in the
clearest possible way, below.
Structures:
struct employee { /* Create the employee structure */
int pid;
char name[4];
char job[40];
int hourlyRate;
int rest;
char *appointments[7];
struct employee *next;
};
Typedefs:
typedef struct employee PERSON;
typedef PERSON *PTR;
And I have a loop in a function calling:
new = (PTR)malloc(sizeof(PERSON)); /* NEW is a PTR as is HEAD */
new->next = head; /* Make the new node link to the first node. */
head = new; /* Make head now point to the new element. */
new->pid = store.pid; /* Fill values with data. */
strncpy(new->name, store.name, 3);
strncpy(new->job, store.job, 40);
new->hourlyRate = store.hourlyRate;
new->rest = (store.rest - 1);
/* THIS LOOP HERE */
for(i = 0; i < 7; i++) {
strcpy(new->appointments, "No booking");
if(i = new->rest) {
strcpy(new->appointments, "BREAK PERIOD");
}
/* THIS LOOP HERE */
}
(Right at the bottom of the post). However the program crashes when it gets
to this line.. Obviously it's somthing to do with the way i am accessing the
array or writing to it.. But im not exactly sure what.. ??
I've given all the code you should need to understand the problem, in the
clearest possible way, below.
Structures:
struct employee { /* Create the employee structure */
int pid;
char name[4];
char job[40];
int hourlyRate;
int rest;
char *appointments[7];
struct employee *next;
};
Typedefs:
typedef struct employee PERSON;
typedef PERSON *PTR;
And I have a loop in a function calling:
new = (PTR)malloc(sizeof(PERSON)); /* NEW is a PTR as is HEAD */
new->next = head; /* Make the new node link to the first node. */
head = new; /* Make head now point to the new element. */
new->pid = store.pid; /* Fill values with data. */
strncpy(new->name, store.name, 3);
strncpy(new->job, store.job, 40);
new->hourlyRate = store.hourlyRate;
new->rest = (store.rest - 1);
/* THIS LOOP HERE */
for(i = 0; i < 7; i++) {
strcpy(new->appointments, "No booking");
if(i = new->rest) {
strcpy(new->appointments, "BREAK PERIOD");
}
/* THIS LOOP HERE */
}