Here is some code
I am trying to read in from radix1.txt a list of 100 6-digit numbers. I then am going to try to radix sort the whole thing and place the results in radix2.txt
Here is some code.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
void main()
{
int i, x, y, z;
char string1[100][6], string2[100][6];
FILE *inFilePtr;
FILE *outFilePtr;
inFilePtr = fopen("radix1.txt", "r");
outFilePtr = fopen("radix2.txt","w");
if(inFilePtr == NULL)
{
printf("Error opening file.\n");
}//end if
else
{
printf("File opened successfully.\n");
printf("Reading and sorting...");
for (x = 0; x < 115; x++)
{
for (i = 0; i < 6; i++)
{
fflush(stdin);
fscanf(inFilePtr,"%c",&string1[x][i]);
printf("%c", string1[x][i]);
}//end for
}//end for
printf("\nRead successful!\n");
/* Test print */
for (z = 0;z < 115; z++)
{
for (i = 0; i < 6; i++)
{
fprintf(outFilePtr,"%c",string1[z][i]);
}//end for
}//end for
for (z = 5; z > -1; z--)
{
for (y = 0; y < 100; y++)
{
if (string1[y][z] > string1[y + 1][z])
{
for (x = 0; x < 6; x++)
{
string2[y][x] = string1[y][x];
string1[y][x] = string1[y + 1][x];
string1[y + 1][x] = string2[y][x];
}//end for
}//end if
}//end for
}//end for
printf("Sort successful!");
for (z = 0;z < 100; z++)
{
for (i = 0; i < 6; i++)
{
printf("%c",string1[z][i]);
fprintf(outFilePtr,"%c",string1[z][i]);
}//end for
printf("\n");
}//end for
printf("\nDone, results are in radix2.txt");
}//end else
fclose(inFilePtr);
fclose(outFilePtr);
}
The problem, so far is that the program only reads in 84 or 85 numbers or so.