指向stuct数据的指针

编程入门 行业动态 更新时间:2024-10-23 02:09:26
本文介绍了指向stuct数据的指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

你好, 我正在研究一个代码,它的数据结构如下: typedef struct { char * infile; char inoptsbuf [10]; char * outfile; } cmdoption_a; cmdoption_a * cmdoption; 和初始化如下: cmdoption-> infile = 1; cmdoption-> outfile = 1; cmdoption-> inoptsbuf =''\ 0''; 我真的很困惑,因为整数是分配给上面的变量吗?!!!! 任何帮助?? !! bob

解决方案

Robert S写道:

hello,我正在调查一个代码,其中包含如下数据结构: typedef struct { char * infile; char inoptsbuf [10]; char * outfile; } cmdoption_a; cmdoption_a * cmdoption; 和初始化如下: c mdoption-> infile = 1; cmdoption-> outfile = 1; cmdoption-> inoptsbuf =''\ 0''; 我真的很困惑因为整数是分配给上面的变量吗?!!!! 任何帮助?? !!

你*应该*混淆;代码(正如你所引用的那样)没有任何意义 ,会(应该?)不能编译,当然也无法工作。 为什么不发布*真*代码(即剪切和粘贴,不要转录)?我是 肯定有人可以解决任何困惑。 HTH, --ag - Artie Gold - 德克萨斯州奥斯汀 it-matters.blogspot (新帖子12/5) www.cafepress/goldsays

thanks 它是一个转码器程序,编译运行没有问题 这里是代码: typedef struct { char * infile; / *输入图像文件。 * / int infmt; / *输入图像文件格式。 * / char * inopts; char inoptsbuf [OPTSMAX + 1]; char * outfile; / *输出图像文件。 * / int outfmt; char * outopts; char outoptsbuf [OPTSMAX + 1]; int verbose; / *详细模式。 * / int debug; int version; int_fast32_t cmptno; int srgb; } cmdopts_t; .. .. .. .. .. cmdopts_t * cmdopts; cmdopts-> infile = 0; cmdopts-> infmt = -1; cmdopts-> inopts = 0; cmdopts-> inoptsbuf [0] =''\'''; cmdopts-> outfile = 0; cmdopts-> outfmt = -1; cmdopts-> outopts = 0; cmdopts-> outoptsbuf [0] =''\ 0''; cmdopts - > verbose = 0; cmdopts-> version = 0; cmdopts-> cmptno = -1; cmdopts- > debug = 0; cmdopts-> srgb = 0; .. .. .. .. " Artie Gold" < AR ******* @ austin.rr>在消息新闻中写道:3c ************* @ individual ...

Robert S写道:

你好, typedef struct { char * infile; char inoptsbuf [10]; char * outfile; } cmdoption_a; cmdoption_a * cmdoption; 和初始化如下: cmdoption-> infile = 1 ; cmdoption-> outfile = 1; cmdoption-> inoptsbuf =''\ 0''; 我真的很困惑,因为整数被分配给以上变量?!!!! 任何帮助?? !!

你*应该*混淆;代码(正如你所引用的那样)毫无意义,(应该?)不能编译,当然也不可能工作。 为什么不发布*真正的*代码(即剪切和粘贴,不要转录)?我确定这里有人可以解决任何困惑。 HTH, --ag - Artie Gold - 德克萨斯州奥斯汀 it-matters.blogspot (新帖子12/5) www.cafepress / goldsays

请不要顶​​尖。你的回复属于下面的,或者用任何引用的文字穿插 。 在原始邮件中,你写道:

typedef struct { char * infile; char inoptsbuf [10]; char * outfile; } cmdoption_a ; cmdoption_a * cmdoption; 和初始化如下: cmdoption-> infile = 1; cmdoption-> outfile = 1; cmdoption-> inoptsbuf =''\ 0'';

但实际代码说(修剪了一下): typedef struct { char * infile; [...] char * outfile; [...] char outoptsbuf [OPTSMAX + 1]; [...]} cmdopts_t; [...] cmdopts_t * cmdopts; cmdopts-> infile = 0; [...] cmdopts-> outfile = 0; [...] cmdopts-> outoptsbuf [0] =''\''';

初始化一个带有1的指针几乎肯定会使没意义,但0 是一个空指针常量。我更喜欢使用宏NULL(在< stddef.h>和其他几个标准头文件中定义 ),但是一个朴素的0 是完全合法的。 这就是为什么最好剪切并粘贴你要求的实际代码,而不是试图解释它;这很容易 意外地改变了你要问的事情。 - Keith汤普森(The_Other_Keith) ks***@mib < www.ghoti/~kst> 圣地亚哥超级计算机中心< *> < users.sdsc.edu/~kst> 我们必须做点什么。这是事情。因此,我们必须这样做。

hello, I am investigating a code,which has data struct deelacration as follow: typedef struct { char *infile; char inoptsbuf[10]; char *outfile; } cmdoption_a; cmdoption_a *cmdoption; and intialization as follow: cmdoption->infile=1; cmdoption->outfile=1; cmdoption->inoptsbuf=''\0''; I am really confused since an integer is assign to the above variables?!!!! any help??!! bob

解决方案

Robert S wrote:

hello, I am investigating a code,which has data struct deelacration as follow: typedef struct { char *infile; char inoptsbuf[10]; char *outfile; } cmdoption_a; cmdoption_a *cmdoption; and intialization as follow: cmdoption->infile=1; cmdoption->outfile=1; cmdoption->inoptsbuf=''\0''; I am really confused since an integer is assign to the above variables?!!!! any help??!!

You *should* be confused; the code (as you''ve quoted it) makes no sense at all, would (should?) not compile and certainly couldn''t possibly work. Why not post the *real* code (i.e. cut and paste, don''t transcribe)? I''m sure someone here could clear up any confusion. HTH, --ag -- Artie Gold -- Austin, Texas it-matters.blogspot (new post 12/5) www.cafepress/goldsays

thanks It is a transcoder proram which compile and run without a problem here is the code: typedef struct { char *infile; /* The input image file. */ int infmt; /* The input image file format. */ char *inopts; char inoptsbuf[OPTSMAX + 1]; char *outfile; /* The output image file. */ int outfmt; char *outopts; char outoptsbuf[OPTSMAX + 1]; int verbose; /* Verbose mode. */ int debug; int version; int_fast32_t cmptno; int srgb; } cmdopts_t; .. .. .. .. .. cmdopts_t *cmdopts; cmdopts->infile = 0; cmdopts->infmt = -1; cmdopts->inopts = 0; cmdopts->inoptsbuf[0] = ''\0''; cmdopts->outfile = 0; cmdopts->outfmt = -1; cmdopts->outopts = 0; cmdopts->outoptsbuf[0] = ''\0''; cmdopts->verbose = 0; cmdopts->version = 0; cmdopts->cmptno = -1; cmdopts->debug = 0; cmdopts->srgb = 0; .. .. .. .. "Artie Gold" <ar*******@austin.rr> wrote in message news:3c*************@individual...

Robert S wrote:

hello, I am investigating a code,which has data struct deelacration as follow: typedef struct { char *infile; char inoptsbuf[10]; char *outfile; } cmdoption_a; cmdoption_a *cmdoption; and intialization as follow: cmdoption->infile=1; cmdoption->outfile=1; cmdoption->inoptsbuf=''\0''; I am really confused since an integer is assign to the above variables?!!!! any help??!!

You *should* be confused; the code (as you''ve quoted it) makes no sense at all, would (should?) not compile and certainly couldn''t possibly work. Why not post the *real* code (i.e. cut and paste, don''t transcribe)? I''m sure someone here could clear up any confusion. HTH, --ag -- Artie Gold -- Austin, Texas it-matters.blogspot (new post 12/5) www.cafepress/goldsays

Please don''t top-post. Your response belongs below, or interspersed with, any quoted text. In your original message, you wrote:

typedef struct { char *infile; char inoptsbuf[10]; char *outfile; } cmdoption_a; cmdoption_a *cmdoption; and intialization as follow: cmdoption->infile=1; cmdoption->outfile=1; cmdoption->inoptsbuf=''\0'';

but the actual code says (trimmed a bit): typedef struct { char *infile; [...] char *outfile; [...] char outoptsbuf[OPTSMAX + 1]; [...] } cmdopts_t; [...] cmdopts_t *cmdopts; cmdopts->infile = 0; [...] cmdopts->outfile = 0; [...] cmdopts->outoptsbuf[0] = ''\0'';

Initializing a pointer with 1 almost certainly makes no sense, but 0 is a null pointer constant. I''d prefer to use the macro NULL (defined in <stddef.h> and several other standard headers), but an unadorned 0 is perfectly legal. This is why it''s best to cut-and-paste the actual code you''re asking about rather than trying to paraphrase it; it''s too easy to accidentally change the very thing you''re asking about. -- Keith Thompson (The_Other_Keith) ks***@mib <www.ghoti/~kst> San Diego Supercomputer Center <*> <users.sdsc.edu/~kst> We must do something. This is something. Therefore, we must do this.

更多推荐

指向stuct数据的指针

本文发布于:2023-07-29 11:04:14,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1240118.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:指针   数据   stuct

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!