malloc()总分配不了空间
#include <stdio.h>
#define SIZE30
struct noname{
char nowfilled;
int count;
};
typedef struct noname Item;
typedef struct node
{
Item item;
struct node* next;
}Node;
typedef Node * List;
List head, pre, current;
List buildchain(void)
{
char willfilled;
head = NULL;
puts("请输入第一个节点:\n");
while (s_gets(willfilled, SIZE) != NULL && willfilled != '\0') //变动部分
{
current = (List)malloc(sizeof(List));
if (current == NULL);
puts("stop\n"); //测试时打印了stop
current->item.count++;
if (head = NULL)
head = current;
else
pre->next = current;
current->next = NULL;
strcpy(current->item.nowfilled, willfilled); //变动部分
eatline();
puts("请输入下一个节点(或输入空行取消):\n");
pre = current;
}
return head;
}
int main(void)
{
List now;
now = buildchain( );
} current = (List)malloc(sizeof(Node)); 我不太清除为什么要用两次转定义,你可以直接在结构体创建的时间,将List加在后面就行了,指针也是可以的··
页:
[1]