[ create a new paste ] login | about

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

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

double fMinPositive(FILE* inFile)
{
	double Min = -1, num;
	while(fscanf(inFile, "%lf", &num) > 0)
	{
		if(num > 0)
		{
			if(Min == -1 || num < Min)
				Min = num;
		}
	}
	return Min;
}
void main()
{
	char* fname = "MinData.txt";
	double Min;
	FILE* fp = fopen(fname, "rt");
	if(fp == NULL)
	{
		printf("File %s not found.\n", fname);
		return;
	}
	Min = fMinPositive(fp);
	if(Min > 0)
		printf("Positive min is %lf.\n", Min);
	else
		printf("Positive number(s) not found!\n");
	fclose(fp);
	getch();
}


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


Create a new paste based on this one


Comments: