I'm trying to sort a list of names alphabetically, by isolating the first element of the string and compare, which I think should work, but there's an error, SISEGV with something about an invalid access to storage... I don't know, but my group mates and I can't figure this out. Can anyone spot anything wrong? Help appreciated. Thanks!
void addGalaxy(ptrUniverse *pFirstG)
{ char cChoice,
cDump;
ptrUniverse pNewG, pNextG, pPrevG;
int nElem = 0, nEnd;
pNewG = malloc(sizeof(struct galaxyTag));
do{
printf("Do you want to add a galaxy? [y/n]");
scanf("%c%c", &cChoice, &cDump);
if(cChoice == 'Y' || cChoice == 'y')
{
printf("Enter Name of Galaxy: ");
gets(pNewG->strGalaxyName);
addSystem(&pNewG->pSolarSystem);
pNewG->pNextGalaxy = NULL;
if(*pFirstG = NULL)
*pFirstG = pNewG;
else
{
pNextG = pNewG;
while(pNewG->strGalaxyName[nElem] != '\0' && pNextG->strGalaxyName[nElem] != '\0')
{
while(pNewG->strGalaxyName[nElem] > pNextG->strGalaxyName[nElem] && pNextG->pNextGalaxy != NULL)
{
pPrevG = pNextG;
pNextG = pNextG->pNextGalaxy;
}
if (pNextG->strGalaxyName[nElem] > pNewG->strGalaxyName[nElem])
{
pPrevG->pNextGalaxy = pNewG;
pNewG->pNextGalaxy = pNextG;
}
else if (pNextG->strGalaxyName[nElem] < pNewG->strGalaxyName[nElem])
pNextG->pNextGalaxy = pNewG;
nElem++;
}
}
}
}while(cChoice != 'n' || cChoice != 'N');
}