[ create a new paste ] login | about

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

C, pasted on Jul 29:
#include<stdio.h>
int main(void)
{
 FILE *fp;
 int n=0;
 char name[100];
 double height, weight, hsum=0.0, wsum=0.0;
 if((fp=fopen("idata.txt","r"))==NULL)
  printf("FILE OPEN ERROR \n");
 else
 {
  while(fscanf(fp, "%s%lf%lf",name, &height, &weight)!=EOF)
  {
   printf("%-8s \t %5.1f %5.1f \n", name, height, weight);
   n++;
   hsum+=height;
   wsum+=weight;
  }
  fclose(fp);
  printf("average \t %5.1f %5.1f \n",hsum/n, wsum/n);
 }
 return 0;
}


Output:
1
FILE OPEN ERROR 


Create a new paste based on this one


Comments: