Hello. This is what in my .txt document.
Code:
Lab 1: 10
Lab 2: 18
Lab 3: 22
Lab 4: 19
Lab 5: 14
Lab 6: 16
Lab 7: 18
Lab 8: 18
Exam 1: 65
Exam 2: 42
I would like to list those number in descending order without changing which test it is:
Let say Lab 1 is 10 points. After listing it in descending order, it would still be Lab 1: 10.
The output would look like this for example:
Lab scores in sorted order:
22 19 18 18 18 16 14 10
How would I go about doing this?
My current code:
Code:
#include <stdlib.h>
#include <stdio.h>
#include <iostream>
#include <ctype.h>
#define MAX 8
void main (void);
void function1 (void);
void function2 (void);
void main (void)
{
function1();
}
void function1 (void)
{
FILE *in;
char var;
float lab [];
float test [];
if (( in = fopen ("grades.txt", "r")) == NULL)
{
printf ("Error Opening File");
return;
}
while ((fscanf(in, "%c", &var)) != EOF)
{
printf ("%c", var);
if (var == ':')
fscanf (in, "%f %f %f %f %f %f %f %f %f %f", &lab[1], &lab[2], &lab[3], &lab[4], &lab[5], &lab[6], &lab[7], &lab[8], &test[1], &test[2])
}
printf ("\n");
}