C语言初学者的一个问题
- C/C++ code
#include "stdafx.h"#include "stdio.h"#define NODE struct StuInfovoid main(){ }struct StuInfo{ int score; struct StuInfo *next;}/*typedef struct StuInfo NODE; */NODE *create() //创建链表{ NODE *head, *tail, *pnew; int score; head = (NODE *)malloc (sizeof(NODE)); //创建头节点 head->next = NULL; //头节点的指针域置NULL tail = head; //开始时尾指针指向头节点 while (1) //创建学生成绩线性链表 { scanf ("%d", &score); //输入成绩 if (score < 0) //成绩为负,循环退出 break; pnew = (NODE *)malloc (sizeof(NODE)); //创建一新节点 pnew->score = score; pnew->next = NULL; tail->next = pnew; tail = pnew; } return (head);}在vc++6.0中执行之后显示以下错误:哪位大侠能告诉我为什么呢
--------------------Configuration: BB - Win32 Debug--------------------
Compiling...
BB.cpp
D:\Program Files\Microsoft Visual Studio\MyProjects\BB\BB.cpp(19) : error C2236: unexpected 'struct' 'StuInfo'
D:\Program Files\Microsoft Visual Studio\MyProjects\BB\BB.cpp(23) : error C2065: 'malloc' : undeclared identifier
执行 cl.exe 时出错.
BB.exe - 1 error(s), 0 warning(s)
[解决办法]
#include <stdlib.h>
[解决办法]
没有包含malloc函数的原型声明~