I am trying to read numbers in from a text file into an array, covert them into Celsius, then print them out. But when I read in the number 212, 32, -1 (on separate lines) for example, it only seems to read in memory locations of the first two numbers and doesn't do the conversion.
#include <stdio.h>
int GetInput(double fahrenheit[]);
void ProcessData(double fahrenheit[], int count, double celcius[]);
void PrintHeading(void);
void OutputResult(double fahrenheit[], int count, double c[]);
int main(void) {
char c;
int i;
double fahrenheit[1000];
double celcius[1000];
int count;
count = GetInput(fahrenheit);
ProcessData(fahrenheit,count,celcius);
OutputResult(fahrenheit,count,celcius);
return 0;
} // main
/*
GetInput read data Fahrenheit degree (double) from keyboard in a 1-dim array F[1000]. It returns # of data entered
*/
int GetInput (double fahrenheit[1000])
{
const int SENTINEL = -1;
int count=0;
while (scanf("%lf", &fahrenheit[count]), fahrenheit[count] != SENTINEL)
{
printf("This code worked %.2lf\n",&fahrenheit[count]);
printf("This is the count %d\n", count);
count++;
}
return count;
}
/*
ProcessData convert from Fahrenheit degrees in fahrenheit[] to Celsius degrees celcius[]
*/
void ProcessData(double fahrenheit[1000], int count, double celcius[1000]){
int i = 0;
for (i =0; i<count;i++)
{
celcius[count] = (fahrenheit[count] - 32.00)/1.8;
}
}
/*
PrintHeading print only headings like below
Fahrenheit Celsius
_________ ______
*/
void PrintHeading(void){
printf(" Fahrenheit Celcius\n __________ _______\n");
}
/*
OutputResult print all degrees under appropriate headings
*/
void OutputResult(double fahrenheit[1000], int count, double celcius[1000])
{
int i =0;
PrintHeading();
for (i=0;i<count;i++)
{
printf(" %d %d\n ",fahrenheit[i],celcius[i]);
}
}