Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3360536
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:00:15+00:00 2026-05-18T03:00:15+00:00

The exact structure of the struct is not important. From what I gather the

  • 0

The exact structure of the struct is not important.

From what I gather the following c code is reading a “chunk” of binary data (equal to the size of the struct) and directly writing that to a struct (i.e first 32 bytes to name, next 2 bytes to attrib, etc). Is there any equivelent in C# managed code?

Please provide a code snipet showing similar outcome. To save time you can simplify the to only a few elements and assume the appropriate filestream type object is already initialized.

Note: I will be consuming an existing legacy data file so the formatting/packing of the existing data file is important. I can’t for example just use .net serialization / deserization because I will be processing legacy existing files (changing format is not feasible).

typedef struct _PDB 
{
   char name[32];
   unsigned short attrib;
   unsigned short version;
   unsigned int created;
   unsigned int modified;
   unsigned int backup;
   unsigned int modNum;
   unsigned int nextRecordListID;
   unsigned short numRecs;
} PDB;

void getFileType(FILE *in) 
{
   PDB p;
   fseek(in, 0, SEEK_SET);
   fread(&p, sizeof(p), 1, in);
. . .
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T03:00:15+00:00Added an answer on May 18, 2026 at 3:00 am

    I think you’re asking about the StructLayoutAttribute and the FieldOffsetAttribute.

    Example (snippet) from MSDN site:

    [StructLayout(LayoutKind.Explicit, Size=16, CharSet=CharSet.Ansi)]
    public class MySystemTime 
    {
       [FieldOffset(0)]public ushort wYear; 
       [FieldOffset(2)]public ushort wMonth;
       [FieldOffset(4)]public ushort wDayOfWeek; 
       [FieldOffset(6)]public ushort wDay; 
       [FieldOffset(8)]public ushort wHour; 
       [FieldOffset(10)]public ushort wMinute; 
       [FieldOffset(12)]public ushort wSecond; 
       [FieldOffset(14)]public ushort wMilliseconds; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need to find the exact size in bytes, occupied by a tree data structure
I have a file that contains the following type and structure of data: <data>
I have a lot of web pages that use the same exact html structure.
Exact duplicate of Function name for creating something if it's not there yet I
The exact warning I get is warning C4715: 'hand::show' : not all control paths
Here is some code: struct K : CGAL::Exact_predicates_inexact_constructions_kernel {}; typedef CGAL::Triangulation_vertex_base_2<K> Vb; typedef CGAL::Constrained_triangulation_face_base_2<K>
The definition of schema is logical structure of data in database. It is owned
Im trying to read an alarm structure from a Beckhoff - PLC into a
I have one problem with this code. I should create one structure and share
I have two tables which have the exact same structure. Both tables can store

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.