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;
}