I am having a small problem with my bubble sort. It will read the file print the current file then maybe or or maybe not does not go into my bubblesort funcion then closes. But i need it to print back out the sorted data. Any ideas and or suggestions please feel free to post. Code is below.
Code:
#include <stdio.h>
#include <string.h>
#define TRUE 1
#define FALSE 0
void bubblesort(char x[][16], char y[][7],int N);
void printlist(char x[][16], char y[][7]);
main()
{
char name1[25][16], name2[25][7];
int i, N;
i=0;
N=0;
FILE *fin, *fout;
fin =fopen("A:\\BubbleSortIn.txt","r");
fout=fopen("A:\\BubbleSortOut.txt","w");
printf("|| Here Is The Unsorted List ||\n\n");
while(fscanf(fin,"%s %s",name1[i],name2[i]) != EOF)
{
printf("%-17s\t%-7s\n",name1[i], name2[i]);
fprintf(fout,"%-17s\t%-7s\n",name1[i], name2[i]);
i = i + 1;
}
printf("\n|| Here Is The Sorted List ||\n\n");
bubblesort(name1, name2, N);
printlist(name1, name2);
fclose(fin);
fclose(fout);
}
void bubblesort(char x[][16], char y[][7],int N)
{
int I, J ,J_End;
char Hold_it_x[16], Hold_it_y[7];
int Done;
J_End = N - 1;
Done = FALSE;
I = 0;
while ((I < N-1) && (!Done))
{
Done = TRUE;
J = 0;
while (J < J_End )
{
if ( strcmp(x[J], x[J+1])> 0)
{
strcpy(Hold_it_x , x[J]);
strcpy( x[J], x[J+1]);
strcpy(x[J+1], Hold_it_x);
strcpy(Hold_it_y, y[J]);
strcpy(y[J], y[J+1]);
strcpy(y[J+1], Hold_it_y);
Done = FALSE;
}
J = J + 1;
}
J_End = J_End - 1;
I = I + 1;
}
}
void printlist(char name1[][16], char name2[][7])
{
int i=0;
int N=0;
while(i < N)
{
printf("%-17s\t%-7s\n",name1[i], name2[i]);
i = i + 1;
}
}