I have problems with searching & sorting strings in a file...
I want to alphabetize the string so I did this
{for(x=0; x<100; x++)
{
for(c=x; c<15; c++)
fscanf(stdin, "%s", student[c]->surname);
if(strcmp(student[c]->surname,student[c+1]->surname)<0)
{strcpy(temp,student[c]->surname);
strcpy(student[c]->surname,student[c+1]->surname);
strcpy(student[c+1]->surname,temp);
strcpy(temp,student[c]->name);
strcpy(student[c]->name,student[c+1]->name);
strcpy(student[c+1]->name,temp);
strcpy(temp,student[c]->number);
strcpy(student[c]->number,student[c+1]->number);
strcpy(student[c+1]->number,temp);}
}
}
when i run the program, it just hangs. but i couldn't think of other ways on how to alphabetize it, other than comparing two strings then swapping. is there something wrong with my code above?
I also can't search properly...
printf("\nEnter first letter of surname to search\n");
gets(search);
fscanf(r, "%s", student[c]->surname);
if(!strncmp(search, student[c]->surname,1))
{printf("\n%s, %s\t%s\n", student[c]->surname, student[c]->name, student[c]->number); break;}
nothing shows up when i enter a letter to search.. it just skips the above code and executes the next step (I didn't pasted it above, it's the printf("\nSearch again\n"); )
I'm really stumped on what to do. Any ideas?