november1992, this is what I tried to test with:
Code:
#include <stdio.h>
void sort(float b[], int size, int direction)
{
float tmp;
int k,lt;
lt= size-1;
if(direction == a){ //ascending
for (k = 0; k < size; k++){
if(b[k]>b[lt]){
tmp = b[i];
b[k] = b[lt];
b[lt] = tmp;
}
}
}
if(direction == c){ //descending
for (k = 0; k < size; k++){
if(b[k]<b[lt]){
tmp = b[k];
b[k] = b[lt];
b[lt] = tmp;
}
}
}
}
void print(float numbers[], int num)
{
int i;
for (i = 0; i < num; ++i)
{
printf("%f ", numbers[i]);
}
putchar('\n');
}
int main(void)
{
float numbers[] = {1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7, 8.8, 9.9};
int num = sizeof(numbers) / sizeof(numbers[0]);
print(numbers, num);
sort(numbers, num, 'd');
print(numbers, num);
sort(numbers, num, 'c');
print(numbers, num);
return 0;
}
Notice how simple is the part that is used to test? No need for file I/O; file I/O can be added later. The whole point is to test the sort function, so I specify the test array in the code and just write to standard output.