Hey guys, When I run my program, all seems to go well, until I try reach my ShowData function. The specific line I have issues with is line 172(tasktrack.cpp). The console will crash when it reaches line 172, I have tried commenting out the line, and that gives me the following garbled output: http://i.imgur.com/8hPILTC.png
Here is the code for the function I where the issue originates:
1 2 3 4 5 6 7 8 9 10 11 12
void TaskTrack::showData(TaskTrack taskList[], int size){
char itemDesc[MAXCHAR];
for (int i = 0; i < size; i++){
courseDesc(taskList[i].course, itemDesc);
cout << setw(15) << left << taskList[i].taskName
<< setw(10) << left << itemDesc
<< setw(5) << taskList[i].dueDate << endl << endl;
}
}
Here is the code for the function call that causes a crash:
itemDesc = "CS161";
This will set itemDesc to point to the array "CS161". You are not allowed to modify this array. Many compilers will warn you because you use a pointer to non-const char to point to const data.
strcpy(itemDesc, "CS161");
This will now try to write to the array that you were not allowed to modify so that's why it crashes.