Im trying to work out the total values of a table, which i have read from a file

x y
1.0 2.876
2.6 4.234
3.7 8.874
4.5 7.698
6.0 9.932

I want to work out the total values of x, i.e sum of.

How would i implement this, please. thanks, here is what i have so far, ive tried to work out the sum using a loop, do i need to use a link list and if so how do i do this, please. Any help will be greatly appreicated. Thanks
#include <stdio.h>
#include <math.h>

int main(void)

	char line [101];
	char *line_ptr;
	double x, y;
	int no_values=-1;
	double sum_x;
	int i=0;
	FILE *input_stream;
	if ((input_stream=fopen("test_data.dat", "r")) != NULL)
		while ((line_ptr=fgets(line, sizeof(line), input_stream))!= NULL)
			if ((sscanf (line, "%d %d", &x, &y)) != 2)
				fprintf (stdout, "%s\n", line);
	fprintf(stdout, "\n\n\n\nno_values: %d\n", no_values);
	for (i=0; i<=no_values; i++)
		sum_x= x;
	fprintf(stdout, "\n\n\n\nsum_x: %lf\n", sum_x);

Last edited by shabbir; 13Dec2006 at 10:54.. Reason: Code formating.