查看: 99|回复: 1
打印 上一主题 下一主题

小弟想在iccavr 7.22版本下后插法建立单链表但是编译不通过

[复制链接] qrcode

1

主题

1

帖子

5

积分

新手上路

Rank: 1

积分
5
楼主
跳转到指定楼层
发表于 2013-12-17 09:54 AM | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
小弟想在iccavr 7.22版本下后插法建立单链表但是编译不通过
程序如下
#include
#include
#include
#include

typedef struct mac_id
{
unsigned char id_num;
unsigned char mac_addr[4];
} mac_id_type;

typedef struct node
{
mac_id_type mi ;
struct node * next ;
}linklist ;
//用尾插法建立一个只有一个几点的单链表
void main(void)
{
unsigned char j = 0;
unsigned char i = 0;
unsigned char r = 0;
unsigned char mstr_id_num = '0';
unsigned char mstr_mac_num[4];
unsigned char slave1_id_num = '1';
unsigned char slave1_mac_num[4];
unsigned char slave2_id_num = '2';
unsigned char slave2_mac_num[4];
linklist *l,*end,*nw;//链表的头指针L 尾指针end 新建节点指针new
mac_id_type macid; //mac_id_type结构体类型的变量
mac_id_type * midp;// 指向mac_id_type结构体类型的指针
macid.id_num = mstr_id_num;//macid变量的属性赋值
l=NULL;// 链表的头指针L首先给个空地址
end=l;// 链表的尾指针指向链表的头指针也为空
mstr_mac_num[0]='0';
mstr_mac_num[1]='0';
mstr_mac_num[2]='0';
mstr_mac_num[3]='0';
slave1_mac_num[0]='0';
slave1_mac_num[1]='0';
slave1_mac_num[2]='0';
slave1_mac_num[3]='1';
slave2_mac_num[0]='0';
slave2_mac_num[1]='0';
slave2_mac_num[2]='0';
slave2_mac_num[3]='2';
for(i=0;i<4;i++)
macid.mac_addr[i]=mstr_mac_num[i];//macid变量的属性赋值
midp = & macid;//mac_id_type结构体类型的指针指向mac_id_type结构体类型的变量
nw=(linklist *)malloc(sizeof(linklist));//分配一块linklist类型字节大小的存储空间 返回空间首地址给新建链表节点指针
nw.mi.id_num = midp.id_num;//新建链表节点的属性赋值
for(r=0;r<4;r++)
nw.mi.mac_addr[r]=midp.mac_addr[r];//新建链表节点的属性赋值
if(!l) //如果头结点不存在
l=nw;//则头指针指向新建节点
else
end.next=nw;//如果头结点已经存在,新建节点的地址给头节点的NEXT指针
end=nw;//尾指针指向新建节点
if(end)//如果链表不为空
end.next=NULL;
}
在单独编译 nw=(linklist *)malloc(sizeof(linklist));时编译不通过
出现如下错误
!ERROR Function 'putchar' not defined. This is a hardware dependent
function,
and it is not included in the ICCAVR default library. Please implement
this function to match your target requirements. You can find examples
of this function under the \examples.AVR directory. Make
a copy of a suitable example, add it to your project and modify it if
needed. The source code must #include the appropriate C header file
(e.g. stdio.h) as it contains the special compiler pragma for 'putchar'.
!误差函数“的putchar”没有定义。这是一个依赖于硬件的功能,
并且它不包含在ICCAVR默认库。请执行
此功能以符合您的目标要求。你可以找到例子
\ examples.AVR目录下此功能。使
一个合适的例子的一个副本,把它添加到你的项目,如果修改
需要的。源代码必须的#include相应的C头文件
(如stdio.h中),因为它包含了特殊的编译器pragma对'的putchar“。
这句程序 nw=(linklist *)malloc(sizeof(linklist)); 是照着书上写的
真不知道哪里错了 就大神指点 万分感谢 感激不已 悬赏价格
20E币
未解决
回复

使用道具 举报

0

主题

11

帖子

24

积分

新手上路

Rank: 1

积分
24
沙发
发表于 2014-1-6 07:43 AM | 只看该作者
单片机用malloc,这个你真的要好好考虑一下,这里有一个类似的案例/bbsdata/danpianji/bzdmlglrgjv10703.HTM,你仔细研究一下                                                                                                                                                                       

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表