自己写的关于简单数据管理的程序,有问题,求指导
题目是这样的:编写有一个程序,该程序输入职工工号和完成的产品数量,程序允许同一职工有多次输入,由程序对其完成的产品数量实现累计。程序按完成数量对他们排序,并确定他们的名次。按完成的产品数量由多到少的顺序,输出名次、同一名次的职工人数及他们的工号(工号由小到大顺序输出)。要求程序用有序链表存储数据信息。
下面是我写的程序,但是里面有问题,我不知道如何改正,请各位高手帮忙。
#define Null 0
#define INF sizeof(struct information)
#include<stdlib.h>
#include<stdio.h>
struct information
{
int num;
int amo;
struct information *next;
};
struct information *creat(int n)
{
struct information *head=NULL,*p1,*p2;
head=p2=(struct information *)malloc(INF);
{
p1=(struct information*)malloc(INF);
p2->next=p1;
p2=p1;
}
p2->next=NULL;
return(head);
}
struct information *solve(struct information*head,struct information *info)
{
struct information *p3,*p4,*p5;
p3=head;
p5=info;
if(head==NULL)
{
head=p5;
p5->next=NULL;
}
else
{
while((p5->num>p3->num)&&(p3->next!=NULL))
{
p4=p3;p3=p3->next;
}
if (p5->num<=p3->num)
{
if(p5->num==p3->num)
p5->num=(p5->num+p5->num);
else p4->next=p5;
p5->next=p4;
}
else
{
p4->next=p5;p5->next=NULL;
}
}
return(head);
}
void main()
{
int a;
char answer,Y,N;
struct information *p;
information *creat();
printf("1.输入内容\n2.查看数据\n");
scanf("%d",&a);
if(a==1)
{
printf ("Input the number and amount\n");
scanf ("%d%d",&p3->num,&p3->amo);
information *solve();
printf("Continue? Y/N?\n");
scanf("%c",&answer);
while (answer=Y)
printf("%d,%d\n",p->num,p->amo);
p=p->next;
}
else
{
do
{
printf("%d %d\n",p->num,p->amo);
p=p->next;
}
while
(p!=NULL);
}
}
错误有三个,分别是
error C2065: 'p3' : undeclared identifier
error C2227: left of '->num' must point to class/struct/union
error C2227: left of '->amo' must point to class/struct/union
对于链表这一块不是很理解,所以不太懂这个问题,请大家帮忙解决,还有就是请问这样写的程序是不是太麻烦了,并且是不是要用到有关文件的语句?
[解决办法]
- C/C++ code
//mian函数中的p3和struct information *solve中的p3是不同的概念,p3只在各个函数中起作用,//不会涉及到其他的函数的使用,由于你在main函数中没有首先定义p3,所以会出现://error C2065: 'p3' : undeclared identifier//所以你在使用scanf ("%d%d",&p3->num,&p3->amo);的时候会出现////error C2227: left of '->num' must point to class/struct/union//error C2227: left of '->amo' must point to class/struct/union