[ create a new paste ] login | about

Link: http://codepad.org/MzowIjQW    [ raw code | output | fork ]

C, pasted on Dec 19:
#include<stdio.h>
#include<conio.h>

double fSum(FILE* inFile)
{
	double sum = 0, num;
	while(fscanf(inFile, "%lf", &num) > 0)
	{
		sum += num;
	}
	return sum;
}

void main()
{
	char* fname = "NumData.txt";
	FILE* fp = fopen(fname, "rt");
	if(fp != NULL)
	{
		double sum = fSum(fp);
		printf("Sum is %lf.\n", sum);
		fclose(fp);
	}
	else
	{
		printf("File %s not found.\n", fname);
	}
	getch();
}


Output:
1
2
3
Line 17: error: conio.h: No such file or directory
In function 'main':
Line 15: warning: return type of 'main' is not 'int'


Create a new paste based on this one


Comments: