Removing uneeded file.
[and.git] / PC^2 / pc2 / samps / sumit.c
blob90dbd13dd782d494322e2361e32a98ed125303db
2 /*
3 * File: sum.c
4 * Purpose: to sum the integers in the file sumit.dat
5 * Author: pc2@ecs.csus.edu or http://www.ecs.csus.edu/pc2
7 * Tue Oct 19 21:32:14 PDT 1999
9 * caveat - this is not nice code, copy at own risk ;)
11 * $Id: sumit.c,v 1.1 2005/03/06 05:13:57 laned Exp $
15 #include <stdio.h>
17 #define INFILENAME "sumit.dat"
19 main ()
21 FILE *fp = fopen (INFILENAME,"r");
22 int sum = 0;
23 int i;
25 if (fp)
27 while (1==fscanf(fp, "%d", &i))
29 sum += i > 0 ? i : 0;
31 fclose (fp);
32 printf("The sum of the positive integers is %d \n",sum);
34 else
36 printf("Could not read from file sumit.dat \n");
41 /* eof */