问题在程序中有显示。。。输入姓名和工资,输出姓名工资,麻烦了
#include <stdio.h>#include <stdlib.h>
#include <string.h>
#define M 15
struct system{
char name[M];
int wage;
struct system *next;
};
int main (void)
{
struct system *head=NULL;
struct system *prev,*current;
char input [M];
puts("请输入员工姓名:");
while(gets(input)!=NULL&&input[0]!='\0')
{
current=(struct system *)malloc(sizeof(struct system));
if(head==NULL)
head=current;
else
prev->next=current;
current->next=NULL;
strcpy(current->name,input);
puts("请输入你的工资:");
scanf("%d",¤t->wage);
while(getchar()!='\n')
continue;
puts("请输入下个员工姓名:");
prev=current;
}
if(head==NULL)
printf("没有输入数据");
else
printf("下面是输出数据\n");
current=head;
while(current!=NULL)
{
printf("姓名:%s 工资:%d\n",current->name,current->wage);
current=current->next;
}
/*这个位置如果添加了一个“current=head;”为什么就不能正常运行了*/
while(current!=NULL)
{
free(current);
current=current->next;
}
printf("ok!");
return 0;
}