请问下为什么动态分配的语句处报一下错误:
implicite declaration of function 'int malloc(...)'
/*
已知一个包含有n个节点的单项环形链表,
编写函数,查找链表中num成员数值最小的
节点,输出该结点的num成员。
*/
#include <string.h>
#include <stdio.h>
struct node{
int num;
struct node *next;
}*head;
int search(struct node *p){
int min = p->num;
while(p->next != head){
if((++p)->num < min)
min = p->num;
}
return min;
}
int main(){
int n = 0,num;
struct node *p1,*p2;
p1 = p2 = (struct node*)malloc(sizeof(struct node));
scanf("%d",&p1->num);
while(p1->num != 0){
n++;
if(n == 1) head = p1;
else p2->next = p1;
p2 = p1;
p1 = (struct node*)malloc(sizeof(struct node));
scanf("%d",&p1->num);
}
p2->next = head;
num = search(head + 1);
printf("%d\n",num);
return 0;
}