[ create a new paste ] login | about

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

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

double fMax(FILE* inFile, int& Error)
{
	Error = 0;
	double Max = 0, num;
	if(fscanf(inFile, "%lf", &num) <= 0)
	{
		Error = 1;
		return Max;
	}
	Max = num;
	while(fscanf(inFile, "%lf", &num) > 0)
	{
		if(num > Max)
			Max = num;
	}
	return Max;
}
void main()
{
	char* fname = "MaxData.txt";
	int Error; double Max;
	FILE* fp = fopen(fname, "rt");
	if(fp == NULL)
	{
		printf("File %s not found.\n", fname);
		return;
	}
	Max = fMax(fp, Error);
	if(!Error)
		printf("Max is %lf.\n", Max);
	else
		printf("Number(s) not found.\n");
	fclose(fp);
	getch();
}


Output:
1
2
3
4
Line 17: error: conio.h: No such file or directory
Line 4: error: expected ';', ',' or ')' before '&' token
In function 'main':
Line 22: warning: return type of 'main' is not 'int'


Create a new paste based on this one


Comments: