<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: read struct from unsigned char [5000] in c program in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/read-struct-from-unsigned-char-5000-in-c-program/m-p/2496851#M830376</link>
    <description>There are a couple ways to do this depending on if you really want to copy the data into the new structure, or if you want to access the char array via a structure pointer.&lt;BR /&gt;&lt;BR /&gt;1) Copy data into new structure&lt;BR /&gt;&lt;BR /&gt;unsigned char arr[5000];&lt;BR /&gt;struct foo foo_struct;&lt;BR /&gt;&lt;BR /&gt;memcpy((void *) &amp;amp;foo_struct, (void *) arr, sizeof(foo_struct));&lt;BR /&gt;&lt;BR /&gt;Now, foo_struct has the same binary data as arr.&lt;BR /&gt;&lt;BR /&gt;2) Access array data via structure pointer.&lt;BR /&gt;&lt;BR /&gt;unsigned char arr[5000];&lt;BR /&gt;struct foo *foo_ptr;&lt;BR /&gt;&lt;BR /&gt;foo_ptr = (struct foo *) arr;&lt;BR /&gt;&lt;BR /&gt;Now, you can access the foo struct pointed to by foo_ptr...&lt;BR /&gt;&lt;BR /&gt;foo_ptr-&amp;gt;member1;&lt;BR /&gt;foo_ptr-&amp;gt;member2;&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;-sam&lt;BR /&gt;</description>
    <pubDate>Wed, 21 Feb 2001 19:52:40 GMT</pubDate>
    <dc:creator>Sam Nicholls</dc:creator>
    <dc:date>2001-02-21T19:52:40Z</dc:date>
    <item>
      <title>read struct from unsigned char [5000] in c program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/read-struct-from-unsigned-char-5000-in-c-program/m-p/2496850#M830375</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;I produced an array of unsigned char and the array contained binary data.  I used to write the data back into a disk file and then read the file into a struct variable.  Is there anyway I could directly read data from the array into the struct variable without writing and reading of a disk file?&lt;BR /&gt;&lt;BR /&gt;Thanks.&lt;BR /&gt;&lt;BR /&gt;Xiaoming</description>
      <pubDate>Wed, 21 Feb 2001 19:03:44 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/read-struct-from-unsigned-char-5000-in-c-program/m-p/2496850#M830375</guid>
      <dc:creator>Xiaoming Zhang</dc:creator>
      <dc:date>2001-02-21T19:03:44Z</dc:date>
    </item>
    <item>
      <title>Re: read struct from unsigned char [5000] in c program</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/read-struct-from-unsigned-char-5000-in-c-program/m-p/2496851#M830376</link>
      <description>There are a couple ways to do this depending on if you really want to copy the data into the new structure, or if you want to access the char array via a structure pointer.&lt;BR /&gt;&lt;BR /&gt;1) Copy data into new structure&lt;BR /&gt;&lt;BR /&gt;unsigned char arr[5000];&lt;BR /&gt;struct foo foo_struct;&lt;BR /&gt;&lt;BR /&gt;memcpy((void *) &amp;amp;foo_struct, (void *) arr, sizeof(foo_struct));&lt;BR /&gt;&lt;BR /&gt;Now, foo_struct has the same binary data as arr.&lt;BR /&gt;&lt;BR /&gt;2) Access array data via structure pointer.&lt;BR /&gt;&lt;BR /&gt;unsigned char arr[5000];&lt;BR /&gt;struct foo *foo_ptr;&lt;BR /&gt;&lt;BR /&gt;foo_ptr = (struct foo *) arr;&lt;BR /&gt;&lt;BR /&gt;Now, you can access the foo struct pointed to by foo_ptr...&lt;BR /&gt;&lt;BR /&gt;foo_ptr-&amp;gt;member1;&lt;BR /&gt;foo_ptr-&amp;gt;member2;&lt;BR /&gt;...&lt;BR /&gt;&lt;BR /&gt;-sam&lt;BR /&gt;</description>
      <pubDate>Wed, 21 Feb 2001 19:52:40 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/read-struct-from-unsigned-char-5000-in-c-program/m-p/2496851#M830376</guid>
      <dc:creator>Sam Nicholls</dc:creator>
      <dc:date>2001-02-21T19:52:40Z</dc:date>
    </item>
  </channel>
</rss>

