结构体字符串输入问题
1:编译运行都没问题的函数#include<stdio.h>
#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<stdio.h>
#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]);
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");
}
===================================================================================
怎么解决赋值后在输入的问题?