Adak, I tried your bubble sort, and the problem persists.
I even tried a separate file, without the first, last, median, and choice of descending or ascending
here it is:
Code:
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
main(){
int i;
int count;
int InputNumbers[100];
int max;
int Temp;
char filename[256];
FILE *in_fd;
FILE *out_fd;
char outputname[256];
float next_number;
printf("Enter input file name:");
scanf("%s",filename);
/* open file and print error message and exit on failure */
if ((in_fd = fopen(filename, "r")) == 0) {
fprintf(stderr, "File: %s Not Found!\n",filename);
exit(0);
}
/*Asks user to name the ouput file, storing it in "outputname"*/
printf("Enter the name of your output file:");
scanf("%s", outputname);
/*Creates output file, and opens it for writing*/
out_fd=fopen(outputname, "w");
/* this while loop reads numbers from the file until it is empty. */
/* It stores these numbers in "InputNumbers" as "count" increments */
/* through the array */
while(fscanf(in_fd,"%f\n",&next_number)!=EOF)
{
count++;
InputNumbers[count]=next_number;
}
max=count;
/*This is a bubble sort. The program increments through the array, */
/*comparing each set of adjacent numbers. It swaps the numbers in */
/*order to satisfy the inequality*/
for (count=0;count < max-1;count++)
{
for(i=count+1;i < max;i++)
{
if(InputNumbers[count] < InputNumbers[i])
{
Temp=InputNumbers[count];
InputNumbers[count]=InputNumbers[i];
InputNumbers[i]=Temp;
}
}
}
return (0);
}
I still get a segmentation fault on it. If i can get it working on its own, then i should be able to put it into the larger code.
also, I got the converter working with this
Code:
#include <stdio.h>
main() {
/* Declare main program variables. Use of float allows for decimal points. */
float number;
char unit;
float m_km_ConvNum;
float km_m_ConvNum;
float M_ft_ConvNum;
float f_M_ConvNum;
/*Program asks the user to type the distance, including units, that they wish*/
/*to be converted*/
printf("Please enter the distance that you wish to convert (including units:(f)eet,(M)iles,(m)eters,(k)ilometers):\n");
/*Program reads the input from the user, sotring them in number and unit*/
scanf("%f %c\n",&number,&unit);
/*The following if statements direct the program to the correct operation, depending*/
/*on the value of unit*/
if(unit=='m'){
m_km_ConvNum=number*.001;
printf("%.3f Meters is equivalent to: %.3f Kilometers\n",number,m_km_ConvNum);
}
if(unit=='K'){
km_m_ConvNum=number*1000;
printf("%.3f Kilometers is equivalent to: %.3f Meters\n",number,km_m_ConvNum);
}
if(unit=='M'){
M_ft_ConvNum=number*5280;
printf("%.3f Miles is equivalent to: %.3f Feet\n",number,M_ft_ConvNum);
}
if(unit=='f'){
f_M_ConvNum=number*.00018939;
printf("%.3f Feet is equivalent to: %.3f Miles\n",number,f_M_ConvNum);
}
return (0);
}
I had to add "&" to unit, is this wrong?
I still, however, have to type end after putting in my distance. after that it works fine. any ideas?