Ask a Question related to UNIX Programming, Design and Development.
-
John Smith #1
Typecaste Question
Hi,
I am using solaris 8. I can't figure out how to copy strings:
The following are defined in a .h file:
-----------------------------------------------------------------------
typedef struct string_type {
union u {
char some_val[32];
int some_val2;
} _u;
}STYPE;
#define DecStr(s_variable) extern STYPE *s_variable
-------------------------------------------------------------------------
This is a simplified version of what I am trying to do:
DecStr(MyId);
unsigned char octet[13];
octet[ 0] = (unsigned char)12;
octet[ 1] = (unsigned char)13;
octet[ 2] = (unsigned char)14;
octet[ 3] = (unsigned char)15;
octet[ 4] = (unsigned char)00;
octet[ 5] = 0x0;
MyId=(STYPE *)octet;
The problem is that MyId doesn't get the values assigned from octet?
Can anyone help me how to caste this string?
Thanks!
John Smith Guest
-
Newbie Question: Biz Card Template Question
Hi, I got the Pagemaker PlugIn - I am using one of the templates for Business Cards - the elements appear to be grouped (bound box all around when I... -
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you
<RonGrossi382872@yahoo.com> wrote in message news:1114393703.900419.199790@f14g2000cwb.googlegroups.com... This is the most important question of... -
David Schwartz #2
Re: Typecaste Question
"John Smith" <John_Smith273@cox.net> wrote in message
news:jjiQa.950$Ze.636@fed1read03...
> I am using solaris 8. I can't figure out how to copy strings:> The following are defined in a .h file:
> -----------------------------------------------------------------------
> typedef struct string_type {
> union u {
> char some_val[32];
> int some_val2;
> } _u;
> }STYPE;This declares a pointer to an STYPE, not an actual STYPE.> #define DecStr(s_variable) extern STYPE *s_variable
This makes MyId a pointer to an STYPE.> This is a simplified version of what I am trying to do:
>
>
> DecStr(MyId);
Umm, 'octet' is NOT an STYPE.> unsigned char octet[13];
>
> octet[ 0] = (unsigned char)12;
> octet[ 1] = (unsigned char)13;
> octet[ 2] = (unsigned char)14;
> octet[ 3] = (unsigned char)15;
> octet[ 4] = (unsigned char)00;
> octet[ 5] = 0x0;
>
> MyId=(STYPE *)octet;
How did you determine this?> The problem is that MyId doesn't get the values assigned from octet?
Can you be more precise about what you're trying to do? If you're trying> Can anyone help me how to caste this string?
to *copy* a string, you need to use some sort of copying function (like
'strcpy').
DS
David Schwartz Guest
-
John Smith #3
Re: Typecaste Question
"David Schwartz" <davids@webmaster.com> wrote in message
news:beshq2$473$1@nntp.webmaster.com...trying>
> "John Smith" <John_Smith273@cox.net> wrote in message
> news:jjiQa.950$Ze.636@fed1read03...
>>> > I am using solaris 8. I can't figure out how to copy strings:>> > The following are defined in a .h file:
> > -----------------------------------------------------------------------
> > typedef struct string_type {
> > union u {
> > char some_val[32];
> > int some_val2;
> > } _u;
> > }STYPE;>> > #define DecStr(s_variable) extern STYPE *s_variable
> This declares a pointer to an STYPE, not an actual STYPE.
>>> > This is a simplified version of what I am trying to do:
> >
> >
> > DecStr(MyId);
> This makes MyId a pointer to an STYPE.
>>> > unsigned char octet[13];
> >
> > octet[ 0] = (unsigned char)12;
> > octet[ 1] = (unsigned char)13;
> > octet[ 2] = (unsigned char)14;
> > octet[ 3] = (unsigned char)15;
> > octet[ 4] = (unsigned char)00;
> > octet[ 5] = 0x0;
> >
> > MyId=(STYPE *)octet;
> Umm, 'octet' is NOT an STYPE.
>>> > The problem is that MyId doesn't get the values assigned from octet?
> How did you determine this?
>>> > Can anyone help me how to caste this string?
> Can you be more precise about what you're trying to do? If you'reThanks for your kind response.> to *copy* a string, you need to use some sort of copying function (like
> 'strcpy').
>
> DS
1) I am trying to copy the string octet into MyId. The framwork I am working
in has a function called DecStrCopy (STYPE *destString, STYPE *srcString).
So somehow I have to cast octet to STYPE.
2) Furthermore, I was wondering if I can completely take octet out of the
picture. I should be able to just use MyId instead of octet above.
Can I do something or a variation like:
*MyId[0] = (unsigned char *)12;
*MyId[1] = (unsigned char *)13;
So on an so forth.
John Smith Guest
-
David Schwartz #4
Re: Typecaste Question
"John Smith" <John_Smith273@cox.net> wrote in message
news:RxnQa.1010$Ze.642@fed1read03...
> Thanks for your kind response.working> 1) I am trying to copy the string octet into MyId. The framwork I amOkay, that's impossible. You can't copy data into a pointer, there's no> in has a function called DecStrCopy (STYPE *destString, STYPE *srcString).
> So somehow I have to cast octet to STYPE.
room.
No, because you never allocated any memory for MyId to point to.> 2) Furthermore, I was wondering if I can completely take octet out of the
> picture. I should be able to just use MyId instead of octet above.
>
> Can I do something or a variation like:
>
> *MyId[0] = (unsigned char *)12;
> *MyId[1] = (unsigned char *)13;
>
> So on an so forth.
DS
David Schwartz Guest
-
John Smith #5
Re: Typecaste Question
"David Schwartz" <davids@webmaster.com> wrote in message
news:bet7l1$h1j$1@nntp.webmaster.com...*srcString).>
> "John Smith" <John_Smith273@cox.net> wrote in message
> news:RxnQa.1010$Ze.642@fed1read03...
>>> > Thanks for your kind response.> working> > 1) I am trying to copy the string octet into MyId. The framwork I am> > in has a function called DecStrCopy (STYPE *destString, STYPEno>> > So somehow I have to cast octet to STYPE.
> Okay, that's impossible. You can't copy data into a pointer, there'sI am sorry I made an error pasting the prototype. It is:> room.
DecStrCopy (STYPE * destString, char * srcString)
John Smith Guest



Reply With Quote

