i am writing a function that reads the content of the file into a dynamically-allocated array of "Point" struct.
Code:
#include <stdio.h>
#include <stdlib.h>
typedef struct{
double x;
double y;
}Point;
void readPoints(char* fileName, int* numPoints){
int i;
FILE *f = fopen(fileName, "r");
if(f != NULL){
fscanf(f, "%d", numPoints);
printf("the first line = %d \n", *numPoints);
Point *poin = (Point*)malloc((*numPoints)*sizeof(Point));
while (!feof(f)){
for(i=0; i<(*numPoints);i++){
fscanf(f, "%f,%f", poin->x, poin->y);
printf("%f , %f\n", poin->x, poin->y);
}
}
fclose(f);
printf("END\n");
free(poin);
}
else{
perror("Could not open..!\n") ;
}
}
the file will look something like this
4
2.35,6.14
5.5,7.0
0.0,-55.9
14084.1,39864
the function compiles fine,,,, but it doesnt output the correct result.. ur help will be appreciated..