Hey, I'm working on this program and I have two modules. One is a job class which contains a name. The other is a scheduling class.
I'm having this problem where I put a job through my job_copy method and the name comes out scrambled-- but it doesn't happen within the job_copy method itself.
Here is my output:
Before job_copy-- name: name2
In job_copy-- name: name2
After job_copy-- name: �D(�����h(��Z���/(��
Here is the relevant code in the Scheduler class:
Code:
Job* SC_removeJob(Scheduler* sc){
/* WHAT IS GOING ON?????? */
Job* j;
printf("Before job_copy-- name: %s\n", sc->job->name);
j = job_copy(sc->job);
printf("After job_copy-- name: %s\n", j->name);
and here is the job_copy method:
Code:
Job* job_copy(Job *j2){
Job* j1 = job_alloc();
char new[5]; /*fix this?? */
j1->name = strcpy( new, j2->name);
j1->startTime = j2->startTime;
j1->CPUTime = j2->CPUTime;
j1->CPUTimeLeft = j2->CPUTimeLeft;
j1->IOOperations = j2->IOOperations;
j1->priority = j2->priority;
j1->timeSlice = j2->timeSlice;
j1->opsPerMs = j2->opsPerMs;
printf("In job_copy-- name: %s\n", j1->name);
return j1;
}
I'm very confused as to where the error is occurring.
Any help = 5 Schrute bucks.
Thanks!