Code:
#include<stdio.h>
#include<stdlib.h>
#define MAX 50
#define MAX_COL 20
#define SCORE 5
int getData(FILE* spData, char name[][MAX_COL], float difficulty[], float score[][SCORE]);
void SelectionSort(FILE* spData, float score[][SCORE ], int);
//int SelectionSort(FILE* spData, char name[][MAX_COL], float difficulty[], float score[][SCORE ], int);
//int Caltotal()
void printData(FILE* spData, char name[][MAX_COL], float difficulty[], float score[][SCORE], int);
int main(void)
{
// variable declarations
FILE*spData;
char name[MAX][MAX_COL];
float difficulty[MAX_COL];
float score[MAX][SCORE];
int numDiver = 0;
int last = MAX_COL;
//statement
if((spData=fopen("DIV1.txt","r"))== NULL)
{
printf("\n Error opennning file!\n");
exit(100);
}
else
{
printf("opened file!\n");
}
numDiver = getData(spData,name, difficulty, score);
SelectionSort(spData, score, last);
printData(spData, name, difficulty, score, numDiver);
fclose(spData);
int i;
scanf("%d", &i);
return 0;
}
/*===============================getdata=====================================
Pre: SpData is oppened,
Post:
*/
int getData(FILE* spData, char name[][MAX_COL], float difficulty[], float score[][SCORE])
{
int i=0;
int j=0;
while (i < MAX && (fscanf(spData,"%c", &name[i][0]) != EOF))
{
for(j = 1; j < MAX_COL; j++)
{
fscanf(spData,"%c", &name[i][j]);
}
fscanf(spData,"%f", &difficulty[i]);
for(j = 0; j < SCORE; j++)
fscanf(spData,"%f\n", &score[i][j]);
i++;
}
return i;
}
/*===============================BubbleSort=====================================
Pre:
Post:
*/
void SelectionSort(FILE* spData, float score[][SCORE ], int last)
{
// Local Declerations
float temp;
int i;
int j;
int smallest;
int walk;
for(i = 0; i < MAX; i++)
{ printf("Processing row %d\n", i);
for(j = 0; j < last; j++)
{
smallest = j;
// inner loop
for (walk = j+1; walk <= last; walk++)
{printf(" - Comparing column %d\n", walk);
if (score[i][walk]< score[i][smallest])
smallest = walk;
// smallest selected
temp = score[i][j];
score[i][j] = score[i][smallest];
score[i][smallest] = temp;
}
}
}
return;
}
/*===============================PrintData=====================================
Pre:
Post:
*/
void printData(FILE* spData, char name[][MAX_COL], float difficulty[], float score[][SCORE], int numDiver)
{
int i;
int j;
for(i = 0; i < numDiver; i++)
{
for (j = 0; j< MAX_COL; j++)
printf("%c", name[i][j]);
printf(" %1.1f", difficulty[i]);
for (j = 0; j< SCORE; j++)
printf(" %1.1f", score[i][j]);
printf("\n\n");
}
return;
}
can anyone help me to fix my sort function's definition> i wanted it to print out this