- 注册时间
- 2004-10-13
- 最后登录
- 2019-5-15
⑧专业
*永恒国度*
- 积分
- 14145
|
这也算是链表吧
#include<stdio.h>
#include<stdlib.h>
struct list
{
int num;
float cash;
struct list *next;
}*head;
void new_record()
{
struct list *newer,*th1;
newer=(struct list *)malloc(sizeof(struct list));
if(head==NULL)
head=newer;
else
{
th1=head;
while(th1->next!=NULL)
th1=th1->next;
th1->next=newer;
}
th1=newer;
printf("please enter the score and number:");
scanf("%d %f",&th1->num,&th1->cash);
th1->next=NULL;
}
void display()
{
struct list *th1;
if(head==NULL)
{
printf("\nthis is empty.\n");
exit(1);
}
else
{
th1=head;
do
{
printf("num:%d\t",th1->num);
printf("cash:%f\n",th1->cash);th1=th1->next;
}while(th1!=NULL);
}
}
void main()
{
char ch;
int flag=1;
head=NULL;
while(flag)
{
printf("'e' if enter nubmer,'l'is list the number:");
ch=getchar();
switch(ch)
{
case 'e':new_record();break;
case 'l':display();break;
default:flag=0;printf("will exit the programming!\n");
}
}
}
执行一次,然后就提示错为
“scanf: floating point formats not linked Abnormal program termination”
然后有人解答过说可能是while重复分配内存空间,所以导致,但是在VC++里的话是可以运行的,那如果在TC里运行应该怎么改才可以呢? |
|