为什么C语言在运行时候出现多余的乱字
# include<stdio.h># include<malloc.h>
struct worker
{
int sgdj; //上岗登记
int jbdj; //加班登记
int gszs; //工时计算
char name[10]; //姓名
char sex[5]; //性别
int age; //年龄
struct worker * next; //下一个指针变量
};
struct worker* creat(int n)
{
int i;
struct worker *p,*phead;
struct worker *pnew;
phead=(struct worker *)malloc(sizeof(struct worker));
p=phead;
p->next=NULL;
for(i=0;i<n;i++)
{
pnew=(struct worker *)malloc(sizeof(struct worker));
printf("请输入第%d个职工的信息:",i+1);
printf("姓名:");
scanf("%s",pnew->name);
printf("n年龄:");
scanf("%d",&pnew->age);
printf("n性别:");
scanf("%s", pnew->sex);
printf("n上岗天数:");
scanf("%d",&pnew->sgdj);
printf("n加班时间(小时):");
scanf("%d",&pnew->jbdj);
pnew->gszs=pnew->sgdj*8+pnew->jbdj;
pnew->next=NULL;
p->next=pnew;
p=pnew;
}
return phead;
}
void output(struct worker * phead)
{
struct worker *p;
p=phead;
printf("全部职工的信息如下:\n");
printf("%-10s%-8s%-8s%-10s%-10s%-10s\n","姓名","性别","年龄","上岗天数","加班时间","总工时");
while(NULL!=p)
{
printf("%-10s%-8s%-8d%-10d%-10d%-10d\n",p->name,p->sex,p->age,p->sgdj,p->jbdj,p->gszs);
p=p->next;
}
}
main()
{
int n;
struct worker *phead;
printf("请输入职工个数,n=");
scanf("%d",&n);
phead=creat(n);
output(phead);
}