I am trying to call my functions in the main part of the program in the C language but I am having trouble with figuring out which parameters are correct in order to get them to work. If someone could point me in the right direction that would be very helpful. This C program reads data from a file then either sorts the floats or int's from low to high or high to low depending on the menu option selected.
#include <stdio.h>
#include <stdlib.h>
struct data {
char color[40];
float engine;
int n;
char make[40];
};
void IntL2H( int a[], int n) {
int i, j, t;
for( i = n - 2; i >= 0; i--) {
for(j = 0; j <= i; j++) {
if(a[j] > a[j + 1]) {
t = a[j];
a[j] = a[j + 1];
a[j + 1] = t;
}
}
}
}
void IntH2L( int a[], int n) {
int i, j, t;
for( i = n - 2; i >= 0; i--) {
for( j = 0; j <= i; j++) {
if(a[j] < a[j +1]) {
t = a[j];
a[j] = a[j + 1];
a[j +1] = t;
}
}
}
}
void FloatL2H(float a[], int n) {
int i, j;
float t;
for(i = n - 2; i >= 0; i--) {
for(j = 0; j <= i; j++) {
if(a[j] > a[j + 1]) {
t = a[j];
a[j] = a[j + 1];
a[j + 1] = t;
}
}
}
}
void FloatH2L(float a[], int n) {
int i, j;
float t;
for(i = n - 2; i >= 0; i--) {
for(j = 0; j <= i; j++) {
if(a[j] , a[j + 1]) {
t = a[j];
a[j] = a[j + 1];
a[j + 1] = t;
}
}
}
}
void readData(struct data *D, int n) {
char color[40];
float engine;
char make[40];
FILE *fp;
int i = 0, counter = 0, len;
fp = fopen("hw2.txt", "r");
if (fp == NULL) {
printf("\n Error unable to open file");
exit(0); }
while(!feof(fp)) {
fscanf(fp, "%s %f %d %s",(D + (n))->color,&(D + (n))-> engine,&(D + (n))->n,(D + (n))->make);
(n)++;
}
fclose(fp);
}
int main () {
int input;
struct data *D;
do {
printf("1. Sort the data by the float vlaue& print high to low\n"
"2. Sort the data by the float value & print low to high\n"
"3. Sort the data by the int value & print high to low\n"
"4. Sort the data by the int value & print low to hugh\n"
"5. Exit\n");
printf("Enter a number\n");
scanf("%d", &input);}
while (input != 5);
do {
switch(input) {
case 1:
FloatH2L(data, n);
break;
}
}
}