#include
#include
#include
struct worker_List
{
char name[20];
char sex[1];//char sex;
long salary;
};
int main()
{
int len = 0;
struct worker_List *str;
int i = 0;
char name[20];
printf ("please input the number of workers:");
scanf ("%d",&len);
str = (struct worker_List *)malloc(len * sizeof(struct worker_List));
for (i=0; i<len; i++)
{
printf("the %dth worker's information:\n",i+1);
printf("the name is:");
scanf("%s",str[i].name);
printf ("the sex is:");
scanf ("%s",str[i].sex);//此处写%c会直接跳过这个输入语句scanf ("%c",&str[i].sex);
printf ("the salary is: ");
scanf ("%d",&str[i].salary);
}
printf ("please input a name:");
scanf ("%s",name);
for (i=0; i<len; i++)
{
if (strcmp(name,str[i].name))
{
printf ("the sex is %s\n",str[i].sex);// printf ("the sex is %c\n",str[i].sex);
printf ("the salary is %d",str[i].salary);
}
}
return 0;
}