Ask a Question related to UNIX Programming, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
  3. #2

    Default 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;
    > #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're trying
    to *copy* a string, you need to use some sort of copying function (like
    'strcpy').

    DS


    David Schwartz Guest

  4. #3

    Default Re: Typecaste Question

    "David Schwartz" <davids@webmaster.com> wrote in message
    news:beshq2$473$1@nntp.webmaster.com...
    >
    > "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're
    trying
    > to *copy* a string, you need to use some sort of copying function (like
    > 'strcpy').
    >
    > DS
    Thanks for your kind response.

    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

  5. #4

    Default Re: Typecaste Question


    "John Smith" <John_Smith273@cox.net> wrote in message
    news:RxnQa.1010$Ze.642@fed1read03...
    > Thanks for your kind response.
    > 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.
    Okay, that's impossible. You can't copy data into a pointer, there's no
    room.
    > 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.
    No, because you never allocated any memory for MyId to point to.

    DS


    David Schwartz Guest

  6. #5

    Default Re: Typecaste Question

    "David Schwartz" <davids@webmaster.com> wrote in message
    news:bet7l1$h1j$1@nntp.webmaster.com...
    >
    > "John Smith" <John_Smith273@cox.net> wrote in message
    > news:RxnQa.1010$Ze.642@fed1read03...
    >
    > > Thanks for your kind response.
    >
    > > 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.
    >
    > Okay, that's impossible. You can't copy data into a pointer, there's
    no
    > room.
    I am sorry I made an error pasting the prototype. It is:

    DecStrCopy (STYPE * destString, char * srcString)


    John Smith Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139