- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- read struct from unsigned char [5000] in c program
Operating System - HP-UX
1820260
Members
2893
Online
109622
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Discussions
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2001 11:03 AM
02-21-2001 11:03 AM
read struct from unsigned char [5000] in c program
Hi,
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?
Thanks.
Xiaoming
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?
Thanks.
Xiaoming
1 REPLY 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-21-2001 11:52 AM
02-21-2001 11:52 AM
Re: read struct from unsigned char [5000] in c program
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.
1) Copy data into new structure
unsigned char arr[5000];
struct foo foo_struct;
memcpy((void *) &foo_struct, (void *) arr, sizeof(foo_struct));
Now, foo_struct has the same binary data as arr.
2) Access array data via structure pointer.
unsigned char arr[5000];
struct foo *foo_ptr;
foo_ptr = (struct foo *) arr;
Now, you can access the foo struct pointed to by foo_ptr...
foo_ptr->member1;
foo_ptr->member2;
...
-sam
1) Copy data into new structure
unsigned char arr[5000];
struct foo foo_struct;
memcpy((void *) &foo_struct, (void *) arr, sizeof(foo_struct));
Now, foo_struct has the same binary data as arr.
2) Access array data via structure pointer.
unsigned char arr[5000];
struct foo *foo_ptr;
foo_ptr = (struct foo *) arr;
Now, you can access the foo struct pointed to by foo_ptr...
foo_ptr->member1;
foo_ptr->member2;
...
-sam
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Learn About
News and Events
Support
© Copyright 2025 Hewlett Packard Enterprise Development LP