求助高手c语言error C2440: '=' : cannot convert from 'int' to 'struct node *'
#defineNULL0#include<stdio.h>#include<malloc.h>#include<stdlib.h>#include<conio.h>typ...
#define NULL 0
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include<conio.h>
typedef struct node
{
float c;/*c 系数*/
int e;/*e 指数*/
struct node * next;
}dnode;
dnode *creat()
{
dnode *h,*p;
int e,i,n;
float c;
h=(dnode*)malloc(sizeof(dnode));
h->next=NULL;
do
{
printf("enter n: ");
scanf("%d",&n);
}while(n<1);
for(i=1;i<=n;i++)
{
printf("enter %d e c: ",i);
scanf("%f%d",&c,&e);
p=(dnode *)malloc(sizeof(dnode));
p->c =c;
p->e =e;
p->next =h->next ;
h->next=p;
}
return h;
}
void swap(dnode *p,dnode *q)
{
float temp;
int temp1;
temp1=p->e;
p->e=q->e;
q->e=temp1;
temp=p->c;
p->c=q->c;
q->c=temp;
}
void sort(dnode *h)
{
dnode *pi,*p1,*p,*q, *a1,*a2;
p=h->next;
while(p->next!=NULL)
p=p->next;
pi=p;
while(pi!=h->next)
{
p1=p->next;
for(p=h->next; p!=pi; p=p->next)
{
q=p->next;
a1=p->e;
a2=p->e;
if(a1>a2)
{
swap(p,q);
p1=p;
}
}
pi=p1;
}
}
dnode *con(dnode *a,dnode *b)
{
int select;
float x;
dnode *p1,*p2,*p,*t;
t=(dnode*)malloc(sizeof(dnode));
t->next =NULL;
printf("1.+\n");
printf("2.-\n");
printf("select (1-2): ");
scanf("%d",&select);
p1=a->next;
p2=b->next;
while(p1&&p2)
{
if(p1->e==p2->e)
{
if(select==1)
x=p1->c+p2->c;
else
x=p1->c-p2->c;
if(x!=0)
{
p=(dnode*)malloc(sizeof(dnode));
p->e=p1->e;
p->c=x;
p->next=t->next;
t->next=p;
}
p1=p1->next;
p2=p2->next;
}
else if(p1->e>p2->e)
{
p=(dnode*)malloc(sizeof(dnode));
p->e=p2->e;
if(select==1)
p->c=p2->c;
else
p->c=(-1)*p2->c;
p->next=t->next;
t->next=p;
p2=p2->next;
}
else
{
p=(dnode*)malloc(sizeof(dnode));
p->e=p1->e;
p->c=p1->e;
p->next=t->next;
t->next =p;
p1=p1->next;
}
}
while(p1!=NULL)
{
p=(dnode*)malloc(sizeof(dnode));
p=p1;
p1=p1->next;
p->next=t->next;
t->next=p;
}
while(p2!=NULL)
{
p=(dnode*)malloc(sizeof(dnode));
p->e=p2->e;
if(select==2)
p->c=(-1)*p2->c;
else p->c=p2->c;
p2=p2->next;
p->next=t->next;
t->next=p;
}
return t;
}
void disp(dnode *h)
{
dnode *p;
p=h->next;
if(p==NULL)
{
printf("0\n");
exit(0);
}
while(p!=NULL)
{
printf("(%3.1f,%d)",p->c,p->e);
p=p->next;
}
printf("\n");
}
void main()
{
dnode *a,*b,*c;
a=creat();
sort(a);
b=creat();
sort(b);
c=con(a,b);
disp(c);
getch();
}
错误提示
error C2440: '=' : cannot convert from 'int' to 'struct node *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
谢谢高手指教 展开
#include<stdio.h>
#include<malloc.h>
#include<stdlib.h>
#include<conio.h>
typedef struct node
{
float c;/*c 系数*/
int e;/*e 指数*/
struct node * next;
}dnode;
dnode *creat()
{
dnode *h,*p;
int e,i,n;
float c;
h=(dnode*)malloc(sizeof(dnode));
h->next=NULL;
do
{
printf("enter n: ");
scanf("%d",&n);
}while(n<1);
for(i=1;i<=n;i++)
{
printf("enter %d e c: ",i);
scanf("%f%d",&c,&e);
p=(dnode *)malloc(sizeof(dnode));
p->c =c;
p->e =e;
p->next =h->next ;
h->next=p;
}
return h;
}
void swap(dnode *p,dnode *q)
{
float temp;
int temp1;
temp1=p->e;
p->e=q->e;
q->e=temp1;
temp=p->c;
p->c=q->c;
q->c=temp;
}
void sort(dnode *h)
{
dnode *pi,*p1,*p,*q, *a1,*a2;
p=h->next;
while(p->next!=NULL)
p=p->next;
pi=p;
while(pi!=h->next)
{
p1=p->next;
for(p=h->next; p!=pi; p=p->next)
{
q=p->next;
a1=p->e;
a2=p->e;
if(a1>a2)
{
swap(p,q);
p1=p;
}
}
pi=p1;
}
}
dnode *con(dnode *a,dnode *b)
{
int select;
float x;
dnode *p1,*p2,*p,*t;
t=(dnode*)malloc(sizeof(dnode));
t->next =NULL;
printf("1.+\n");
printf("2.-\n");
printf("select (1-2): ");
scanf("%d",&select);
p1=a->next;
p2=b->next;
while(p1&&p2)
{
if(p1->e==p2->e)
{
if(select==1)
x=p1->c+p2->c;
else
x=p1->c-p2->c;
if(x!=0)
{
p=(dnode*)malloc(sizeof(dnode));
p->e=p1->e;
p->c=x;
p->next=t->next;
t->next=p;
}
p1=p1->next;
p2=p2->next;
}
else if(p1->e>p2->e)
{
p=(dnode*)malloc(sizeof(dnode));
p->e=p2->e;
if(select==1)
p->c=p2->c;
else
p->c=(-1)*p2->c;
p->next=t->next;
t->next=p;
p2=p2->next;
}
else
{
p=(dnode*)malloc(sizeof(dnode));
p->e=p1->e;
p->c=p1->e;
p->next=t->next;
t->next =p;
p1=p1->next;
}
}
while(p1!=NULL)
{
p=(dnode*)malloc(sizeof(dnode));
p=p1;
p1=p1->next;
p->next=t->next;
t->next=p;
}
while(p2!=NULL)
{
p=(dnode*)malloc(sizeof(dnode));
p->e=p2->e;
if(select==2)
p->c=(-1)*p2->c;
else p->c=p2->c;
p2=p2->next;
p->next=t->next;
t->next=p;
}
return t;
}
void disp(dnode *h)
{
dnode *p;
p=h->next;
if(p==NULL)
{
printf("0\n");
exit(0);
}
while(p!=NULL)
{
printf("(%3.1f,%d)",p->c,p->e);
p=p->next;
}
printf("\n");
}
void main()
{
dnode *a,*b,*c;
a=creat();
sort(a);
b=creat();
sort(b);
c=con(a,b);
disp(c);
getch();
}
错误提示
error C2440: '=' : cannot convert from 'int' to 'struct node *'
Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
谢谢高手指教 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询