c语言输入输出

#include "stdio.h"
int main()
{
 FILE *fp;
 int ninzu=0;
 char name[100];
 double hsum=0.0;
 double wsum=0.0;
 double height;
 double weight;
 if((fp=fopen("C:\\Users\\USER\\Desktop\\abc.txt","r")==NULL))
  printf("\a文件打开失败 \n");
  else{
   
   while(fscanf(fp,"%s%lf%lf",name,&height,&weight)==3){
   printf("%10s %5.1f %5.1f\n",name,height,weight);
   ninzu++;
   hsum +=height;
   wsum +=weight;   
   }
 printf("--------------------\n");
 printf("平均 %5.1f %5.1f",hsum/ninzu,wsum/ninzu);
 fclose(fp);
  }
  return 0;

}

#include "stdio.h"
int main()
{
 
 int ch;
 FILE *fp;
 char fname[64];
 printf("文件名:");
 scanf("%s",fname);
  if((fp=fopen(fname,"r"))==NULL)
 printf("文件打开失败");
 else{
  while((ch=fgetwc(fp))!=EOF )
  putchar(ch);
  fclose(fp);
 }

 
 
    return 0;
}

posted @ 2014-03-11 15:58  kin2321  阅读(240)  评论(0编辑  收藏  举报