ok i have a project due wedsnday i am trying to sort a list of structures...when i run the program i get a segmentation fault..please help
Code:void exchangeSmallest (STUDENT student[], int i, int last) { /* Local Definitions */ int walker; int smallest; STUDENT tempData = {"", "", 2, "123-45-6789", {0,0,0}}; /* Statements */ smallest = i; for (walker = i + 1; walker <= last; walker++) if (strcmp(student[walker].lName, student[smallest].lName) == 0) { if (strcmp(student[walker].fName, student[smallest].fName) == 0) { if (strcmp(student[walker].ssn, student[smallest].ssn) < 0) { smallest = walker; } } else { if (strcmp(student[walker].fName, student[smallest].fName) < 0) { smallest = walker; } } } else { if (strcmp(student[walker].fName, student[smallest].fName) < 0) { smallest = walker; } } strcpy(tempData.fName, student[i].fName); strcpy(tempData.lName, student[i].lName); tempData.grade = student[i].grade; strcpy(tempData.ssn, student[i].ssn); tempData.bDate.month = student[i].bDate.month; tempData.bDate.date = student[i].bDate.date; tempData.bDate.year = student[i].bDate.year; strcpy(student[i].fName, student[smallest].fName); strcpy(student[i].lName, student[smallest].lName); student[i].grade = student[smallest].grade; strcpy(student[i].ssn, student[smallest].ssn); student[i].bDate.month = student[smallest].bDate.month; student[i].bDate.date = student[smallest].bDate.date; student[i].bDate.year = student[smallest].bDate.year; strcpy(student[smallest].fName, tempData.fName); strcpy(student[smallest].lName, tempData.lName); student[smallest].grade = tempData.grade; strcpy(student[smallest].ssn, tempData.ssn); student[smallest].bDate.month = tempData.bDate.month; student[smallest].bDate.date = tempData.bDate.date; student[smallest].bDate.year = tempData.bDate.year; printf("%s", student[smallest].fName); return; } /*===================================prtArr=================================*/ void prtArr(STUDENT* student, int numRecords) { int i; char* Name; printf("\n%26sName Level SSN Birthdate"," "); printf("\n%26s---- ----- --- ---------"," "); for (i = 0; i < numRecords; i++) { strcat(strcat(strcpy(Name, student[i].fName), " "), student[i].lName); printf("\n%30s %9d %13s %02d/%02d/%4d", Name, student[i].grade, student[i].ssn, student[i].bDate.month, student[i].bDate.date, student[i].bDate.year); } printf("\n\n"); }



LinkBack URL
About LinkBacks


