Struct,char数组和指针问题。 [英] Struct, char array and pointer problem.
本文介绍了Struct,char数组和指针问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
展开 | 选择 | Wrap | 行号
推荐答案
在初始化函数中,您有s-> charArray_B = s_initial。但是s_initial是一个局部变量。
你需要在堆上分配它。
我建议创建一个创建函数a)创建你的堆上的struct变量,b)调用initialize来初始化所有struct成员,c)返回该struct变量的地址。然后写一个删除来释放struct变量
在main()中:
In your initialize function you have s->charArray_B = s_initial. But s_initial is a local variable.
You need to allocate this on the heap.
I suggest a create function that a) creates your struct variable on the heap, b) calls initialize to initialize all the struct members and c) returns the addressof that struct variable. Then write a delete to free the struct variable
In main():
展开 | 选择 | 换行 | 行号
我管理(有点)解决它。这是正确的方法吗?
I managed (kinda) to solve it. Is it the right way?
展开 | 选择 | Wrap | < span class =codeLinkonclick =LineNumbers(this);>行号
s_initial中没有字符串。即使它确实如此,strlen也会返回最多三个。
如果它是你想要的4,那么代码4.如果这是可变的,那么这里是'我可以使用Create()函数的参数:
s_initial does not have a string in it. Even if it did, strlen would return a maximum of three.
If it''s 4 that you want, then code 4. If this is variable, then here''s where I wouild use an argument for the Create() function:
展开 | 选择 | Wrap | 行号
这篇关于Struct,char数组和指针问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文