Это несколько исправленная версия вашей программы.Компилируется почти без ошибок.
Внимательно читайте комментарии, начинающиеся с ***
.
Возможно, ошибок больше, но это начало.
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define LAT_1 -78.98214
#define LONG_1 -7.31600
#define R_PI 3.14159 // *** correct and put PI with more decimals
#define DEGREES 180
int read_file(int i);
double toRadian(double theta); // *** correct declaration
double distance(double d); // *** correct declaration
int main()
{
int i = 0;
return read_file(i);
}
double toRadian(double theta)
{
double x; // *** no need to initialize with 0
x = R_PI / DEGREES; // *** something is missing here: up to to find what
// Hint: you need to use the theta parameter
return x;
}
double distance(double d) // ** correct prototype
{
/* This function is designed to calculate the distance between the check-in
POI and the reference point provided*/
double dist, angle_distance, chord_length;
double lat_2, long_2; // *** double here
char length[256];
char* token[6];
if (fgets(length, 256, stdin) != NULL)
{
token[0] = strtok(length, " ");
int i = 0;
double dist;
for (i = 1; i < 6; i++) // *** what's the purpose of this for loop???
{
lat_2 = atof(token[1]); // *** using atof here
long_2 = atof(token[2]);
}
chord_length = pow(sin(toRadian(lat_2 - LAT_1) / 2) + cos(toRadian
(LAT_1)) * cos(toRadian(lat_2)) * pow(sin(toRadian(long_2 -
LONG_1)))); // *** no idea what the formula should be , but pow needs 2 arguments
angle_distance = 2 * atan2(sqrt(chord_length), sqrt(1 - chord_length)); // *** using chord_length
dist = 6371 * angle_distance; // *** using angle_distance
return dist; // *** the function must return something.
}
} // *** this } was missing
int read_file(int i) // *** what's the purpose if the i parameter?
{
/* This function takes the data from the input file,reading and printing the
User ID, Location (longitude and latitude), Date, Time, and Distance*/
char length[256];
char* token[6];
if (fgets(length, 256, stdin) != NULL)
{
token[0] = strtok(length, " ");
int i = 0;
double dist;
for (i = 1; i < 6; i++)
token[i] = strtok(NULL, " "); /*C programming is fun*/
printf("Stage 1\n==========\n");
printf("User: #%s\n", token[0]);
printf("Location: <%s, %s>\n", token[1], token[2]);
printf("Date: %s\n", token[3]);
printf("Time: %s\n", token[4]);
printf("Distance to reference: %2.2f\n", distance(dist));
}
else
{
printf("Error opening file. Check file and try again.");
exit(EXIT_FAILURE);
}
return 0;
}