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 8301405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:56:10+00:00 2026-06-08T16:56:10+00:00

I have a struct in C typedef struct config { char terminal_id[4]; char update_version[6];

  • 0

I have a struct in C

    typedef struct config
{
    char terminal_id[4];
    char update_version[6];
    char sub_app[6];
    char day[6];
    char month[6];
    char year[6];
    char hours[6];
    char minutes[6];

};

I want to transfer the array of config written in C (as above ) to a struct in C# , I only have byte type data receiving in C# sockets .any idea ?

  • 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-06-08T16:56:12+00:00Added an answer on June 8, 2026 at 4:56 pm

    Since you are in control of the structure, and know how many fields it have, it should be easy to send the strings “as is” but include the terminating '\0' character so you know when one string ends and the next begins (or the message ends for the last string).

    On the receiving end just read one character at a time appending to the correct field, when you receive a character that is zero (not '0' but the literal value 0) then you know one string ends and the next begins (or the whole structure if you received the last string).

    You can use this as C# strings do not have to be allocated beforehand. Another solution instead of having the string-terminators transmitted, would be to first send a fixed-size integer containing the length of the string.

    Edit: If the structure on the receiving C# side have the strings as fixed-size byte arrays, then you can still use the algorithm I proposed. Read one character at a time, and do e.g. struct.buffer1[i++] = ch;. When the array is full, or you receive the string terminator, reset the counter (i in my example before) and start receiving the next string. Remember, if the string is longer than the received string, you have to continue read characters until the string ends, but just discard them.

    The other solution I mention, to prepend each string with its length might be more effective though, as best case you only have to do two writes on the C side and two reads on the C# side. To not have to worry about byte-order, send the length as a fixed-length text field, e.g. to send the string "foobar" you actually send two strings " 6" and "foobar". On the receiving end, first do a single read of four characters, convert the string to an integer, and use that value as the length for the actual string.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a struct like this typedef struct bookStruct { char title[80]; char author[80];
If I have a struct like this: typedef struct { unsigned char c1; unsigned
I have a struct like so, typedef struct Player { char *name; char *heroID;
I have a struct: typedef struct _n { int type; union { char *s;
I have a struct as below typedef struct _someStruct { int V1; char V2[10];
I have a struct like so typedef struct person { int id; char name[20];
I have this struct: #define sbuffer 128 #define xbuffer 1024 typedef struct{ char name[sbuffer];
I have this struct typedef struct grade { char firstName[SIZE]; char lastName[SIZE]; int stuNum;
I have the following struct: typedef struct{ int vin; char* make; char* model; int
I have this struct: typedef struct { void (*func)(instruction); union { double db; char

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.