完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,我的指针有问题。这是我的问题:我有两个函数和一个声明,这是一个结构。一个函数包含在另一个函数中。我想用指针修改这两个函数中的结构。这个代码有效,但不是我想要的。当我试图把指针放进函数1时,编译程序不想编译…我需要这样的东西:谢谢你的帮助。
以上来自于百度翻译 以下为原文 Hi, I have a problem with pointers. Here is my problem : I have two function and one declaration which is a structure. One function is included in the other function. I would like to modify the structure in the two functions by using pointers. void main(void) { // declarations Type_structure My_structure= {0x01 , 0x00, 0x00, 1, 0, 0, 0, 0, 0}; //typedef // Initialize the device SYSTEM_Initialize(); while(1) { function_1(My_structure); } } void function_1(Type_structure My_struct){ function_2(&My_struct); } This code works, but it's not what I want. When I tried to put a pointer into function_1, the compilator doesn't want to compile... I need something like that : void main(void) { // declarations Type_structure My_structure= {0x01 , 0x00, 0x00, 1, 0, 0, 0, 0, 0}; //typedef // Initialize the device SYSTEM_Initialize(); while(1) { function_1(&My_structure); } } void function_1(Type_structure *My_struct){ function_2(&My_struct); } Thank you for your help. |
|
相关推荐
18个回答
|
|
试试这个
以上来自于百度翻译 以下为原文 try this void function_1(Type_structure* My_struct); void function_2(Type-structure* My_struct2); void main(void) { // declarations Type_structure My_structure= {0x01 , 0x00, 0x00, 1, 0, 0, 0, 0, 0}; //typedef // Initialize the device SYSTEM_Initialize(); while(1) { function_1(&My_structure); } } void function_1(Type_structure* My_struct) { function_2(My_struct); } void function_2(Type-structure* My_struct2) { // do something with My_struct2 } |
|
|
|
对不起,拼写错误,无法编辑
以上来自于百度翻译 以下为原文 sorry, typos and couldn't edit void function_2(Type_structure* My_struct2); void function_2(Type_structure* My_struct2) { // do something with My_struct2 } |
|
|
|
谢谢你的回复,但没用。我想我得用双指针了?你觉得双指针怎么样?
以上来自于百度翻译 以下为原文 Thank you for ur reply but it doesn't work. I think I have to use a double pointer ? what do you think about double pointers ? |
|
|
|
不管用吗?你想让它做什么?还是不编译?发布你的实际代码并解释你想要达到的目标。不确定你的双指针是什么意思。
以上来自于百度翻译 以下为原文 doesn't work? what do you want it to do? or doesn't compile? post your actual code and explain what you want to achieve. not sure what you mean by double pointers. |
|
|
|
|
|
|
|
它不编译。现在我返回这个结构,但如果我成功地完成了我想做的事情,那就更好了。如果我有时间的话,我会回来的。非常感谢你!祝你度过美好的一天
以上来自于百度翻译 以下为原文 It doesn't compile. For the moment I return the struct but it would have been better If i had succeed with the thing that I wanted to do . I will come back here if I have some time ... Thank you very much ! And have a nice day :D |
|
|
|
|
|
|
|
函数2(Type结构*)位于哪里?它甚至知道你的Type结构吗?
以上来自于百度翻译 以下为原文 Where is function_2(Type_Structure*) located? Does it even know about your Type_Structure? |
|
|
|
函数原型应该是全局的,或者是包含马丁的。第2页:“你怎么看待双指针?”他们还好吧,你觉得麦当劳怎么样?
以上来自于百度翻译 以下为原文 Function prototypes should be global at the top or from an include.h like martin explained. post #2. "What do you think about double pointers ?" They are ok, what do you think of McDonalds? |
|
|
|
|
|
|
|
没有TyBufff,你每次都需要“StReXXX”,其中“XXX”是TaGyType是眼睛糖果,我更喜欢它。标签是可选的。问候,戴夫
以上来自于百度翻译 以下为原文 Without typedef, you need the "struct xxx" every time, where "xxx" is the tag struct _stag { int x1; int x2; int x3; }; void function_1(struct _stag* My_struct); void function_2(struct _stag* My_struct2); void system_init(void); void main(void) { // declarations struct _stag My_structure = {42, 1, 0}; int i; system_init(); for (i = 0; i < 10; i++) { function_1(&My_structure); printf("%dn", My_structure.x3); } while (1) {} } void function_1(struct _stag* s) { s->x1 = s->x2; s->x2 = s->x3; function_2(s); } void function_2(struct _stag* s) { s->x3 = s->x1 + s->x2; } Typedef is eye candy; I like it much better. The tag is optional. typedef struct { int x1; int x2; int x3; } stype; void function_1(stype* My_struct); void function_2(stype* My_struct2); void system_init(void); void main(void) { // declarations stype My_structure = {42, 1, 0}; int i; system_init(); for (i = 0; i < 10; i++) { function_1(&My_structure); printf("%dn", My_structure.x3); } while (1) {} } void function_1(stype* s) { s->x1 = s->x2; s->x2 = s->x3; function_2(s); } void function_2(stype* s) { s->x3 = s->x1 + s->x2; } Regards, Dave |
|
|
|
指向指针,他可以毁灭世界。
以上来自于百度翻译 以下为原文 Pointer to pointers. const char *say={"Klatuu","Barada","Nikto"}; activateGort(say); activateGort(const char **Gort){ puts(*Gort++); puts(*Gort++); puts(*Gort++); } He could destroy the World. |
|
|
|
指向指针,他可以毁灭世界。
以上来自于百度翻译 以下为原文 Pointer to pointers. const char *say={"Klatuu","Barada","Nikto"}; activateGort(say); activateGort(const char **Gort){ puts(*Gort++); puts(*Gort++); puts(*Gort++); } He could destroy the World. |
|
|
|
你缺少数组的括号:或者更好:
以上来自于百度翻译 以下为原文 You're missing brackets for the array:const char *say[]={"Klatuu","Barada","Nikto"};or better:const char * const say[]={"Klatuu","Barada","Nikto"}; |
|
|
|
我是故意这样做的,看看你能不能认出它。咧嘴笑:
以上来自于百度翻译 以下为原文 I did that on purpose to see if you would spot it. grin: |
|
|
|
|
|
|
|
|
|
|
|
你可以试试这样的东西
以上来自于百度翻译 以下为原文 You can try something like this struct my_struct{ int i; int j; int k; }; void f2 (my_struct *structure) { structure->j = 20; } void f1 (my_struct *structure) { structure->i = 10; f2(structure); } int main (void) { my_struct example = {1, 2, 3}; f1(&example); printf("i = %d , j = %d, k = %d",example.i,example.j,example.k); return 0; } |
|
|
|
只有小组成员才能发言,加入小组>>
5125 浏览 9 评论
1984 浏览 8 评论
1914 浏览 10 评论
请问是否能把一个ADC值转换成两个字节用来设置PWM占空比?
3148 浏览 3 评论
请问电源和晶体值之间有什么关系吗?PIC在正常条件下运行4MHz需要多少电压?
2212 浏览 5 评论
694浏览 1评论
580浏览 1评论
有偿咨询,关于MPLAB X IPE烧录PIC32MX所遇到的问题
462浏览 1评论
PIC Kit3出现目标设备ID(00000000)与预期的设备ID(02c20000)不匹配。是什么原因
599浏览 0评论
493浏览 0评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-1 08:40 , Processed in 1.509228 second(s), Total 113, Slave 96 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号