2개의 데이터 파일을 읽어 이름을 오름차순으로 정렬하여 파일에 출력하는 프로그램을 작성하라. 반드시 연결리스트를 사용해야 한다.

...라는 문제입니다.

어떻게 코드를 짜긴 짰는데, 계속 막히네요.. 한수 가르쳐주시길 바랍니다.

#include <stdio.h>
#include <conio.h>
#include <process.h>

typedef struct student
{
        int number;
        char name[15];
        int age;
        char country[10];
        char department[10];
        struct student *next;
}STUDENT;

void concatenate (STUDENT *first, STUDENT *second);
void bubble (STUDENT *first);

void main()
{
        STUDENT std1[20] = {{NULL, 0, NULL, NULL},};
        STUDENT std2[20] = {{NULL, 0, NULL, NULL},};
        FILE *fpin, *fpout;
        int i=0;

        if ((fpout = fopen ("c:d0801.dat", "r")) == NULL)
        {
                printf ("File open error..n");
                getch();
                exit (-1);
        }
        if ((fpout = fopen ("c:d0901.out", "w")) == NULL)
        {
                printf ("File open error..n");
                getch();
                exit (-1);
        }
        while (!feof (fpin))
        {
                fscanf (fpin, "%s", std1[i].name);
                fscanf (fpin, "%d", &std1[i].age);
                fscanf (fpin, "%s", std1[i].country);
                fscanf (fpin, "%s", std1[i].department);
                std1[i].next = &std1[i+1];
                i++;
        }
        while (!feof (fpout))
        {
                fscanf (fpout, "%s", std2[i].name);
                fscanf (fpout, "%d", &std2[i].age);
                fscanf (fpout, "%s", std2[i].country);
                fscanf (fpout, "%s", std2[i].department);
                std2[i].next = &std2[i+1];
                i++;
        }
        std1[i].next = NULL;
        std2[i].next = NULL;

        concatenate (std1, std2);
        bubble (std1);

        fclose (fpin);
        fclose (fpout);
}

void concatenate (STUDENT *first, STUDENT *second)
{
        if (first->next == NULL)
                first->next = second;
        else
                concatenate (first->next, second);
}
void bubble (STUDENT *stptr)
{
        int i, j;
        char temp[20];

        for (i=0; i<20; i++)
        {
                for (j=-1; j<20; j++)
                {
                        if (stptr[j].name < stptr[j+1].name)
                        {
                                temp = stptr[j].name;
                                stptr[j].name = stptr[j+1].name; // 여기서 계속 막힙니다.
                                stptr[j+1].name = temp;
                        }
                }
        }
}