如何return一个值?
#include "stdafx.h"#include "stdio.h"
#include "stdlib.h"
#define OK 1
#define ERROR -1
#define NULL 0
#define OVERFLOW -2
typedef int ElemType;
typedef int Status;
#define LIST_INIT_SIZE 100
#define LISTINCREMENT 10
typedef struct node
{
int data;
struct node *next;
}Linklist;
Linklist * createlist(int n)
{
int k;
Linklist *head,*r,*p;
head=p=(Linklist *)malloc(sizeof(Linklist));
head->next=NULL;
for(k=1;k<=n;k++)
{
r=(Linklist *)malloc(sizeof(Linklist));
printf("input value:\n");
scanf("%d",&(r->data));
r->next=NULL;
p->next=r;
p=r;
}
return (head);
}
void Printlist(Linklist *head)
{
Linklist *p;
p=head->next;
while(p!=NULL)
{
printf("%4d",p->data);
p=p->next;
}
printf("\n");
}
Linklist *insert(Linklist *head,int i,int k)//这个插入函数在return值有问题
Linklist *p;
Linklist *s;
int j=0;
p=head;
while(p&&j<i-1)
{
p=p->next;
j++;
}
if(!p||j>i-1)
{
return ERROR;//这个return值有问题,应该如何return?
}错误的提示error C2440: 'return' : cannot convert from 'const int' to 'struct node *'
s=(Linklist *)malloc(sizeof(Linklist));
s->data=k;
s->next=p->next;
p->next=s;
return p;
}
Linklist *find(Linklist *head,int i)
{
int j;
Linklist *p;
p=head->next;
j=1;
while(p!=NULL&&j<i)
{
p=p->next;
j++;
}
printf("\n");
return p;
}
int main(int argc, char* argv[])
{
Linklist *L;
Linklist *q;
Linklist *head;
int x;
int k;
int select;
int i=0;
L=createlist(5);
Printlist(L);
printf("input i:\n");
scanf("%d",&i);
printf("input k:\n");
scanf("%d",&k);
insert(L,x,k);
Printlist(L);
printf("input i:\n");
scanf("%d",&i);
q=find(L,i);
printf("%d",q->data);
printf("\n");
return 0;
}