请告诉我wat是我的代码中的问题 [英] Plz tell me wat is the problem in my code
本文介绍了请告诉我wat是我的代码中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
typedef struct ListItem
{
char* Serial_Number;
struct ListItem *pstNextListItem
}ListItem_t;
ListItem_t ListItem;
ListItem_t *stoNext;
stoNext = ListItem.pstNextListItem;
*str_ID = stoNext->Serial_Number;
printf("%s",str_ID);
问题是
str_ID的值是打印一些垃圾值,而不是实际值.
the problem is that
The value of str_ID is printing some junk value and not the actual value.
Can anyone please rectify the problem?
推荐答案
您需要创建实例以使指针指向:
You need to create instances for the pointers to point at:
ListItem_t ListItem;
//---Add these lines
ListItem next;
ListItem.pstNextListItem = &next;
//---
ListItem_t *stoNext;
stoNext = ListItem.pstNextListItem;
依此类推,要使用SerialNumber字段,您将需要为其分配一些东西,依此类推...
And so forth, to use the SerialNumber field, you will need to assign something to that, and so on...
首先,在其中初始化ListItem.pstNextListItem
的地方?您尝试用ListItem.pstNextListItem
初始化stoNext
,而ListItem.pstNextListItem
本身从未被初始化.也许您做到了,但没有显示代码行?
其次,应将str_ID
声明为char* str_ID
.
—SA
First, whereListItem.pstNextListItem
is initialized? You try to initializestoNext
byListItem.pstNextListItem
which itself is never initialized. Maybe you did it but did not show the code line?
Secondly,str_ID
should be declaredchar* str_ID
.
—SA
确保*str_ID
有足够的内存,以便可以容纳字符串.
之后,您可以使用
Make sure*str_ID
have enough memory so that it can hold the string.
After that you can use
memset(str_ID,0x00,256)
或类似的方法.
这篇关于请告诉我wat是我的代码中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文