Code:
#include <stdio.h>
int get_corners(FILE * inp, double x[], double y[], int z);
int output_corners(FILE * out, double x[], double y[], int z);
int poly_area(FILE * inp, double x[], double y[], int z);
int main()
{
FILE *inp;
FILE *out;
double x[7], y[7];
int k;
inp = fopen("file.txt", "r");
k = get_corners(inp, x, y, 5);
out = fopen("out.txt", "w");
k = output_corners(out, x, y, 5);
return (0);
}
int get_corners(FILE * inp, double x[], double y[], int z)
{
int i = 0, points; /* you only ever assign points, test it as well */
points = fscanf(inp, "%lf %lf", &x[i], &y[i]);
for (i = 0; i < 5; i++);/* This ; will hurt you */
{
printf(inp, "%lf , %lf\n", x[i], y[i]);
points = fscanf(inp, "%lf%lf", &x[i], &y[i]);
}
return (i);
}
int output_corners(FILE * out, double x[], double y[], int z)
{
int i = 0, points;
points = fprintf(out, "%lf %lf", x[i], y[i]);
while (points != NULL) { /* NULL is not one of the return values */
printf(out, "%lf %lf\n", x[i], y[i]);
i++;
points = fprintf(out, "%lf %lf", x[i], y[i]);
}
return (i);
}
First off, maximise the warning level of the compiler (or get gcc) and pay attention to what it says.