#include <stdio.h>
#include<ctype.h>
int read(); 请问一下,这里形参应该怎样写啊?
int main()
{
struct student
{
char name[20];
int id;
float class1;
float class2;
float class3;
};
struct student stu[5];
int i;
float ave[5],total=0;
char NAME,ID,AVE;
FILE *outfile = fopen("stud.txt","w");
FILE *infile;
for(i=0;i<5;i++){
printf("Please input the %d student\n",i+1);
printf("Name:");
scanf("%s",&stu[i].name);
printf("ID:");
scanf("%d",&stu[i].id);
printf("Class1:");
scanf("%f",&stu[i].class1);
printf("Class2:");
scanf("%f",&stu[i].class2);
printf("Class3:");
scanf("%f",&stu[i].class3);
total+=stu[i].class1+stu[i].class2+stu[i].class3;
ave[i]=total/3.0;
}
printf(" %-10s%-10s%-10s\n","NAME","ID","AVE");
fprintf(outfile," %-10s%-10s%-10s\n","NAME","ID","AVE");
for(i=0;i<5;i++)
{
// printf("The %d student:%-10s%-10d%-10.2f",i+1,stu[i].name,stu[i].id,ave[i]);
fprintf(outfile,"The %d student:%-10s%-10d%-10.2f\n",i+1,stu[i].name,stu[i].id,ave[i]);
//printf("\n");
}
read(); 这里的实参又应该这样写啊?
return 0;
}
int read()
{ FILE *outfile;
static char name[20];
float i,j,k,m;
outfile=fopen("stud.txt","r");
if(outfile==NULL)
printf("Failed to open the file!");
else
while (fscanf(outfile,"The %d student:%s%d%f",name,&i,&j,&k)!=EOF)
printf("The %d student:%-10s%-10d%-10.2f\n",i,name,j,k);
fclose(outfile);
return 0;
}
----------------解决方案--------------------------------------------------------
int read(int x); //函数声明,x=形参
void main()
{
int a;
read(a); //函数调用,a=实参
}
int read(int x) //x=形参
{
return x*x; //函数体
}
----------------解决方案--------------------------------------------------------
不对啊!read()是一个读文件的作用,应该不能用int吧!还有我编译了运行也是错的!~~
----------------解决方案--------------------------------------------------------
大家帮我看一下啊
----------------解决方案--------------------------------------------------------
个人认为不用写参数
----------------解决方案--------------------------------------------------------
如果不写参数,那就掉用不了下面的程序啊!
----------------解决方案--------------------------------------------------------
结构体最好定义到main函数外,否则read函数不能使用
----------------解决方案--------------------------------------------------------
原来read函数没用结构体啊.算我没说 呵呵
----------------解决方案--------------------------------------------------------
没看你代码唉.只是回答你问题
你参数没写参数,你调用得时候当然也不能凭空传一个进去啊
----------------解决方案--------------------------------------------------------