sorting problem??? help please...

Status
Not open for further replies.

jdesai18

Right off the assembly line
hey guys,

i am doin this program for sorting two-dimnsional aray in ascendin order, and it should accpt N inputs from user... whr N is 7

this is what i have done so far....

void sortLastNames(char name[][N], int N)
{
int count, count1;
char tempname[20];
for(count=0; count<N-1;count++)
{
for(count1=count+1;count1<N;count1++)
{
if(strcmp(name[count], name[count1])>0)
{
strcpy(tempname, name[count]);
strcpy(name[count], name[count1]);
strcpy(name[count1], tempname);
}
}
}
}

now problem is it runs smoothly if u enter input with upto 6 characters, if u enter more than that, it crashes....

please guys reply me back ASAP...
 
Last edited:

nightcrawler

Broken In
hey guys,
void sortLastNames(char name[][N], int N)

This is the reason for it. The above statement means that sortLastNames takes an array of Strings (or 2d array of char). The size of each string is N that is 7. Hence whenever a string greater than 7 is encountered strcmp and strcpy will cause problems.(They have overflow issues as they look for NULL terminating strings '\0').

Fixing this will solve ur problem.
 
Status
Not open for further replies.
Top Bottom