如何获得contiki中列表的最后一项? [英] How do I get the last item of a list in contiki?

查看:89
本文介绍了如何获得contiki中列表的最后一项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Contiki列表函数中,没有用于访问列表的最后一项的功能。我们是否需要使用for循环访问最后一项?



我尝试过:



Hi, In Contiki list functions there is no function for accessing the last item of a list. Do we need to use a for loop to access the last item?

What I have tried:

struct record *n;

for(n = list_head(record_list); n != null; n = n>next)
{
                if(n->next == null){
       printf("last record = %s \n",n->message );
               }


}

推荐答案

看起来像一个链表,没有魔法跳转到列表的最后一个元素,唯一的解决方案是用循环跳转每个元素。



你的代码错了,将 n> next 替换为 n-> next
It is looking like a linked list, there is not magic to jump to last element of list, the only solution is to hop on each element with a loop.

Your code is wrong, replace n>next with n->next.


参见< a href =http://contiki.sourceforge.net/docs/2.6/a01682.html#ga4e96242bd922c2c7116b2e5a5ca7011b> Contiki 2.6:链接列表库 [ ^ ]。


这篇关于如何获得contiki中列表的最后一项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆