1:编译运行都没问题的函数
#include
#define FORMAT "%d\n%s\n%f\n%f\n%f\n"
struct student
{
int num;
char name[20];
float score[3];
};
struct student stu;
void main()
{
void print(struct student *);
scanf("%d%s%f%f%f",&stu.num,stu.name,&stu.score[0],&stu.score[1],&stu.score[2]);
print(&stu);
getch();
}
void print(struct student *p)
{
printf(FORMAT,p->num,p->name,p->score[0],p->score[1],p->score[2]);
printf("\n");
}
==================================================================================
2:编译能通过,但运行有问题
eg:输入:123 lili 89 89 89
回车:控制台关闭。
问题呢?
#include
#define FORMAT "%d\n%s\n%f\n%f\n%f\n"
struct student
{
int num;
char name[20];
float score[3];
};
struct student stu;
void main()
{
void print(struct student *);
struct student *s;
s = &stu;
scanf("%d%s%f%f%f",&s->num,s->name,&s->score[0],&s->score[1],&s->score[2]);
/***
**scanf("%d%s%f%f%f",&s.num,s.name,&s.score[0],&s.score[1],&s.score[2]);
**此写法错误
***/
print(s);
getch();
}
void print(struct student *p)
{
printf(FORMAT,p->num,p->name,p->score[0],p->score[1],p->score[2]);
printf("\n");
}
===================================================================================
在vc上可以
在wintc上不能通过.
我晕。
===================================================================================
#define NUM 4
/*#define SUB_NUM 1 */
#include
#define FORMAT "%d\n%s\n%f\n%f\n%f\n"
struct student
{
int num;
char name[20];
float score[3];
};
struct student stu[4];
void main()
{
int i;
void print(struct student *);
struct student *s;
s = stu;
for(i=0;i<4;i++){
scanf("%d%s%f%f%f",&s->num,s->name,&s->score[0],&s->score[1],&s->score[2]);
s++;
}
printf("\n");
s = stu;
for(i=0;i<4;i++){
print(s);
s++;
}
getch();
}
void print(struct student *p)
{
printf(FORMAT,p->num,p->name,p->score[0],p->score[1],p->score[2]);
printf("\n");
}
另外一个程序
阅读(2399) | 评论(0) | 转发(0) |