一个最简单的工资表
麻烦大家帮我看看这个工资表应该怎么做 很简单 但是那些函数还没学 职工工资表
建立一个链表 每个节点包含的成员有:职工号和工资,用malloc函数开辟新结点,要求链表包含5个结点,,从键盘输入结点的有效数据,然后把这些结点的数据打印出来,用creat函数来建立结点,用list函数来输出数据,这五个职工号码为1.2.3.4.5

程序代码:/*******************************************************************************
职工工资表
建立一个链表 每个节点包含的成员有:职工号和工资,用malloc函数开辟新结点,
要求链表包含5个结点,,从键盘输入结点的有效数据,然后把这些结点的数据打印出
来,用creat函数来建立结点,用list函数来输出数据,这五个职工号码为1.2.3.4.5
*******************************************************************************/
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#define C {char c;while(c=getchar()!='\n');}
struct ST
{
int ID;
float money;
struct ST *next;
}*p,*pr,*head;
void creat()
{
int i=1;
float _money;
while(i<6)
{
printf("input NO.%d wage:\n",i);
scanf("%f",&_money);
C;
if(_money<=0)
continue;
p=(struct ST*)malloc(sizeof(struct ST));
if(p==NULL) exit(0);
p->ID=i;
p->money=_money;
p->next=NULL;
if(i==1)
{
head=p;
pr=p;
}
else
{
pr->next=p;
pr=p;
}
i++;
p->next=NULL;
}
}
void list()
{
int i=0;
for(p=head;i<5;p=p->next,i++)
printf("%5d%10.2f\n",p->ID,p->money);
}
int main(void)
{
creat();
list();
p=head;
while(p->next!=NULL) /*也不知道这么释放内存对不对?请各位指教 */
{
free(p);
p=p->next;
}
}
