473,786 Members | 2,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pointer to stuct data

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
Nov 14 '05 #1
13 1333
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
http://it-matters.blogspot.com (new post 12/5)
http://www.cafepress.com/goldsays
Nov 14 '05 #2
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*******@aust in.rr.com> wrote in message news:3c******** *****@individua l.net...
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
http://it-matters.blogspot.com (new post 12/5)
http://www.cafepress.com/goldsays

Nov 14 '05 #3
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_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #4
Thanks
So 0 means NULL,however I thought '\0' means NULL
Now,how about -1 which assign as follows:

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;
"Keith Thompson" <ks***@mib.or g> wrote in message
news:ln******** ****@nuthaus.mi b.org...
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_Keit h) ks***@mib.org
<http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*>
<http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.

Nov 14 '05 #5

Robert S wrote:
Thanks
So 0 means NULL,however I thought '\0' means NULL
Now,how about -1 which assign as follows:


'\0' in a char sense means ascii zero. 0 in a char* sense means memory
address 0x0, or NULL.

Nov 14 '05 #6
"Robert S" <b_******@yahoo .com> writes:
Thanks
So 0 means NULL,however I thought '\0' means NULL
Now,how about -1 which assign as follows:

[snip]

Again, please don't top-post. And please don't send me copies of
Usenet articles by e-mail.

-1 is just the integer value -1. I believe all the members to which
-1 is assigned are integers. What -1 means is up to the application.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #7
"Jason" <ma******@hotma il.com> writes:
Robert S wrote:
Thanks
So 0 means NULL,however I thought '\0' means NULL
Now,how about -1 which assign as follows:


'\0' in a char sense means ascii zero. 0 in a char* sense means memory
address 0x0, or NULL.


ASCII is just one possible character representation. '\0' is a
character constant with value 0 (a null character). It happens to be
of type int, but it's used for clarity in a character context.

A null pointer is not necessarily address 0x0 (i.e., it's not
necessarily represented as all-bits-zero).

Please read section 5 of the C FAQ,
<http://www.eskimo.com/~scs/C-faq/top.html>.

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #8

Keith Thompson wrote:
"Jason" <ma******@hotma il.com> writes:
'\0' in a char sense means ascii zero. 0 in a char* sense means memory address 0x0, or NULL.
ASCII is just one possible character representation. '\0' is a
character constant with value 0 (a null character). It happens to be
of type int, but it's used for clarity in a character context.


Of course, I forgot about other charsets.
A null pointer is not necessarily address 0x0 (i.e., it's not
necessarily represented as all-bits-zero).
I had no idea...
Please read section 5 of the C FAQ,
<http://www.eskimo.com/~scs/C-faq/top.html>.


According to section 5.5 of the FAQ, "it is the compiler's
responsibility to generate whatever bit pattern the machine uses for
that null pointer."

Thanks for setting me straight.

-Jason

Nov 14 '05 #9
Robert S wrote:

Part 1.1 Type: Plain Text (text/plain)
Encoding: quoted-printable


HTML or mime in newsgroups, ignored. This is a text only medium

--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
2270
by: lawrence | last post by:
I had some code that worked fine for several weeks, and then yesterday it stopped working. I'm not sure what I did. Nor can I make out why it isn't working. I'm running a query that should return 3 items from the database. I then get a count of the return, which correctly tells me that I've got 3 items. I then go into a for loop which I expect to loop 3 times and print out the 3 items. Here is where things get strange: it loops 3 times and...
52
5667
by: Douglas Garstang | last post by:
I can't believe I've been trying to work this out for hours now, and I can't believe I couldn't find someone asking for a similar solution in the newsgroups. No wonder I hate C so much, and every time I get the textbooks out end up throwing them against the wall in rage. Thats been going on for 10 years now. Anyway, I have: typedef struct _record { int age;
6
4857
by: someone | last post by:
I have *thought* that setjmp/longjmp() should take a pointer to jmp_buf. And the calling function should hold the actual struct data. But ... I trid on both Win32 and Linux, it seems that setjmp/longjmp() are taking stuct: c:\> dmc sj.c (Digital Mars Compiler Version 8.38n) link sj,,,user32+kernel32/noi; c:\> sj.exe sizeof(jmp_buf) = 64 ----------------------------------------------------------------- sj.c
20
2118
by: j0mbolar | last post by:
I was reading page 720 of unix network programming, volume one, second edition. In this udp_write function he does the following: void udp_write(char *buf, <everything else omitted) struct udpiphdr *ui; struct ip *ip; ip = (struct ip *) buf;
5
5620
by: leaf | last post by:
consider these functions: void foo() { cout << "foo() called; } void sayhello( std::string& msg ){ msg = "something"; } int add( int x, int y) {
27
8978
by: Erik de Castro Lopo | last post by:
Hi all, The GNU C compiler allows a void pointer to be incremented and the behaviour is equivalent to incrementing a char pointer. Is this legal C99 or is this a GNU C extention? Thanks in advance. Erik
26
3065
by: Bill Reid | last post by:
Bear with me, as I am not a "professional" programmer, but I was working on part of program that reads parts of four text files into a buffer which I re-allocate the size as I read each file. I read some of the items from the bottom up of the buffer, and some from the top down, moving the bottom items back to the new re-allocated bottom on every file read. Then when I've read all four files, I sort the top and bottom items separately...
13
11994
by: william | last post by:
code segment: long int * size; char entry; ............. size=&entry; ************************************* Gcc reported 'assignment of incompatible pointer type'.
10
2878
by: kkirtac | last post by:
Hi, i have a void pointer and i cast it to an appropriate known type before using. The types which i cast this void* to are, from the Intel's open source computer vision library. Here is my piece of non- working code: CvMat *rowVect = cvCreateMat(1,nfeatures,CV_MAKETYPE(images- //rowVect is a pointer to CvMat type cvReshape( images, rowVect, 0, 1 ); //vectorize the image; readrow is a 1xN matrix(vector)
0
9496
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10164
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9961
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8989
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7512
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6745
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3669
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.