/* 用indata()输入职工的信息并且用outdata()输出 */
#include "stdio.h"
#include "conio.h"
struct employee
{
int num;
char name[10];
char sex;
float base,stru,total;
};
void indata(struct employee *);
float wages(float,float);
void outdata(struct employee);
main()
{
struct employee member;
indata(&member);
member.total=wages(member.base,member.stru);
outdata(member);
getch();
}
void indata(struct employee *p)
{
float temp;
printf("\nPlease input NO. :");
scanf("%d",&(*p).num);
getchar(); /*此处getchar接收上面的回车,我不明白没有它
下面为什么运行就会出错?*/
printf("\nInput name:");
gets(p->name); /* 我想用scanf("%s",(*p).name); 发现可以正常运行,
但是用scanf("%s",&(*p).name);竟然也可以?? */
printf(" \nInput SEX:");
scanf("%c",&(*p).sex);
printf("\nInput basewage :");
scanf( "%f",&temp); /*为什么非要定义一个temp??我想用scanf("%f",&(*p).base);
形式直接输入basewage和struwage为什么又出错??*/
p->base=temp;
printf("\nInput struwage :");
scanf( "%f",&temp);
p->stru=temp;
}
float wages(float a,float b)
{ float t;
t=a+b;
return(t);
}
void outdata(struct employee em)
{ printf("NO.:%d\n",em.num);
printf("Name:%s\n",em.name);
printf("Sex:%c\n", em.sex);
printf("basewage:%f\t,strutwage:%f\t,totalwage:%f",
em.base,em.stru,em.total);
}
/* indata()我改成这样了 ,为什么不行??
void indata(struct employee *p)
{
float temp;
printf("\nPlease input NO. :");
scanf("%d",&(*p).num);
getchar();
printf("\nInput name:");
scanf("%s",(*p).name);
printf(" \nInput SEX:");
scanf("%c",&(*p).sex);
printf("\nInput basewage :");
scanf( "%f",&(*p).base);
printf("\nInput struwage :");
scanf( "%f",&(*p).stru);
}
*/