Hey guys, I'm working on my programming assignment. I think everything is fine and dandy, and when I try to compile and run the program it crashes. Then I use the debugger, and get an error that prevents the debugger from working correctly I suppose. I'm not really sure what it is, but it's a segmentation fault apparently.

The whole program is supposed to read from an input file that's formatted as:

n (number of cases)

Last First (names)

GBAnalyzed

planetsDiscovered

etc...

The planets have different types depending on the number; and if there is a planet that had been discovered, the x,y, and z coordinates will be next to it.

I don't know much more explaining that I could do, if there's a question I'd be happy to explain details of the assignment in detail but I really just want to find out what this segmentation fault is.

Also, I apologize for the lengthy post in advance, and thank you to anyone that can help.

Code:#include <stdio.h> #include <stdlib.h> #include <string.h> #include <math.h> typedef struct GeocentricCelestialReferenceFrame{ int x; int y; int z; }GCRF; typedef struct DiscoveredPlanet{ int usersConfirmed; int type; GCRF *coordinates; struct DiscoveredPlanet *next; }DiscPlanet; typedef struct VerifiedPlanet{ int type; GCRF*coordinates; struct VerifiedPlanet *next; } VerPlanet; typedef struct UserWorkCompleted{ char firstName[20]; char lastName[20]; int gbAnalyzed; int planetsDiscovered; struct UserWorkCompleted *next; }UserWork; typedef enum{ NONE = 0, GAS = 1, ICE = 2, STORM = 3, BARREN = 4, TEMPERATE = 5, LAVA = 6, OCEANIC = 7, PLASMA = 8, UNKNOWN = 9 }Planets; UserWork *add(char *, char *, int, int, int, int, int, UserWork *, DiscPlanet *, VerPlanet *); void addDiscPlanet(int, int, int, int, DiscPlanet *, VerPlanet *); void addVerPlanet(int, int, int, int, DiscPlanet *, VerPlanet *); int main() { FILE *fin; int numElements, planet, GB, x1 = 0, y1 = 0, z1 = 0; char lname[20], fname[20]; UserWork *head; DiscPlanet *discHead; VerPlanet *VerHead; VerHead = (VerPlanet *)malloc(sizeof(VerPlanet)); discHead = (DiscPlanet *)malloc(sizeof(DiscPlanet)); head = (UserWork *)malloc(sizeof(UserWork)); head = NULL; discHead = NULL; VerHead = NULL; fin = fopen("GridComputing.in", "r"); if(fin == NULL) { printf("File could not be found."); return 1; } fscanf(fin, "%d ", &numElements); while(!feof(fin)) { fscanf(fin, "%s ", lname); fscanf(fin, "%s ", fname); fscanf(fin, "%d ", &GB); fscanf(fin, "%d ", &planet); if(planet > 0) { fscanf(fin, "%d %d %d", &x1, &y1, &z1); } head = add(lname, fname, GB, planet, x1, y1, z1, head, discHead, VerHead); } UserWork *curr; DiscPlanet *currDisc; VerPlanet *currVer; curr = head; currDisc = discHead; currVer = VerHead; printf("Users:\n"); while(curr->next!=NULL) printf("\t%s, %s - Analalyzed:%d Discovered:%d\n", curr->lastName, curr->firstName, curr->gbAnalyzed, curr->planetsDiscovered); printf("\nDiscovered Planets:\n"); while(currDisc->next!=NULL) printf("\t(%d,%d,%d) - Type:%d\n", currDisc->coordinates->x, currDisc->coordinates->y, currDisc->coordinates->z, currDisc->type); printf("\nVerified Planets:"); while(currVer->next !=NULL) printf("\t(%d,%d,%d) - Type:%d\n", currVer->coordinates->x, currVer->coordinates->y, currVer->coordinates->z, currVer->type); return 0; } UserWork* add(char *lname, char *fname, int GB, int planet, int x1, int y1, int z1, UserWork*head, DiscPlanet *discHead, VerPlanet *VerHead) { UserWork *curr, *append; curr = head; if(head == NULL) { append = (UserWork *)malloc(sizeof(UserWork)); append->next = NULL; strcpy(append->firstName, fname); strcpy(append->lastName, lname); if(planet > 0) { append->planetsDiscovered = 1; addDiscPlanet(planet, x1, y1, z1, discHead, VerHead); return head; } else append->planetsDiscovered = 0; } while(curr->next!=NULL) { if(strcmp(lname, curr->lastName) == 0) { if(strcmp(fname, curr->firstName) == 0) curr->gbAnalyzed+=GB; else if(strcmp(fname, curr->firstName) > 0) { append = (UserWork *)malloc(sizeof(UserWork)); append->next = curr->next; curr->next = append; strcpy(append->firstName, fname); strcpy(append->lastName, lname); if(planet > 0) { append->planetsDiscovered = 1; addDiscPlanet(planet, x1, y1, z1, discHead, VerHead); return head; } else append->planetsDiscovered = 0; } else if(strcmp(fname, curr->firstName) < 0) { append = (UserWork *)malloc(sizeof(UserWork)); append->next = curr; curr = append; strcpy(append->firstName, fname); strcpy(append->lastName, lname); if(planet > 0) { append->planetsDiscovered = 1; addDiscPlanet(planet, x1, y1, z1, discHead, VerHead); return head; } } } } return head; } void addDiscPlanet(int planet, int x1, int y1, int z1, DiscPlanet *discHead, VerPlanet *VerHead) { struct DiscoveredPlanet *curr, *next; if(discHead == NULL) { discHead->coordinates->x = x1; discHead->coordinates->y = y1; discHead->coordinates->z = z1; discHead->type = planet; discHead->usersConfirmed = 1; discHead->next = NULL; } else if(discHead != NULL) { curr = discHead; while(curr->next!=NULL) { if(curr->coordinates->x == x1 && curr->coordinates->y == y1 && curr->coordinates->z == z1 && curr->type == planet) { curr->usersConfirmed+=1; if(curr->usersConfirmed > 2) addVerPlanet(planet, x1, y1, z1, discHead, VerHead); return; } curr = curr->next; } next = (DiscPlanet *)malloc(sizeof(DiscPlanet)); curr->next = next; next->next = NULL; } } void addVerPlanet(int planet, int x1, int y1, int z1, DiscPlanet *discHead, VerPlanet *VerHead) { VerPlanet *curr, *append; DiscPlanet *curr1, *del; int distanceList, distanceNew; distanceNew = sqrt((x1*x1)+(y1*y1)+(z1*z1)); if(VerHead == NULL) { VerHead->type = planet; VerHead->coordinates->x = x1; VerHead->coordinates->y = y1; VerHead->coordinates->z = z1; } else if(VerHead!=NULL) { curr = VerHead; while(curr->next!=NULL) { distanceList = sqrt((curr->coordinates->x)*(curr->coordinates->x) + (curr->coordinates->y)*(curr->coordinates->y) + (curr->coordinates->z)*(curr->coordinates->z)); if(distanceNew < distanceList) { append = (VerPlanet *)malloc(sizeof(VerPlanet)); append->type = planet; append->coordinates->x = x1; append->coordinates->y = y1; append->coordinates->z = z1; append->next = curr->next; curr = append; return; } else { append = (VerPlanet *)malloc(sizeof(VerPlanet)); append->type = planet; append->coordinates->x = x1; append->coordinates->y = y1; append->coordinates->z = z1; curr->next = append; append->next = NULL; return; } } append = (VerPlanet *)malloc(sizeof(VerPlanet)); append->type = planet; append->coordinates->x = x1; append->coordinates->y = y1; append->coordinates->z = z1; curr->next = append; append->next = NULL; } curr1 = discHead; while(curr1->next!=NULL) { if(discHead->coordinates->x == x1 && discHead->coordinates->y == y1 && discHead->coordinates->z == z1 && discHead->type == planet) { discHead = curr1->next; free(curr1); curr1 = curr1->next; } else if(curr1->coordinates->x == x1 && curr1->coordinates->y == y1 && curr1->coordinates->z == z1 && curr1->type == planet) { del->next = curr1->next; free(curr1); } del = curr1; curr1 = curr1->next; } }