I have written a function which reads Data from a file and calculates the distance between each point.
Code:
int read(float Wert1, float Wert2, char *filename);
int read(float Wert1,float Wert2, char *filename)
{
FILE *infile;
infile = fopen(filename,"r");
if (infile==NULL)
{perror("Error:No file found");
}
int i;
float x0,x1,quadrx,y0,y1,quadry,betr;
for(i=0;fscanf(infile,"%f %f",&Wert1,&Wert2)!=EOF;i++)
{
if(i>0)
{
x0 = x1-Wert1;
quadrx = x0*x0;
y0 = y1-Wert2;
quadry = y0*y0;
betr = sqrt(quadrx+quadry);
printf("X1-Wert: %f\n X2-Wert: %f\n Y1-Wert: %f\n Y2-Wert %f\n",x1,Wert1,y1,Wert2);
printf("Abstand: %f\n",betr);
}
else(printf("Anfangswert X1 %lf\n Anfangswert Y1 %lf\n",Wert1,Wert2));
x1 = Wert1;
y1 = Wert2;
}
int size = i;
return size ;
}
I now want to write a different function which needs the distance. Since I used floating numbers instead of an array (which was on purpose) I now want to pass my function read to another function so that all values can be used there. Is there any way of doing that in c?