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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:53:26+00:00 2026-06-11T13:53:26+00:00

I been working in a project for my Data Networks class and they ask

  • 0

I been working in a project for my Data Networks class and they ask me to concatenate a header like this:

struct ip
{
    unsigned long a;
    unsigned long b;
    unsigned int l;
} IP;

And a message which it’s a char* let’s say “Hello”.

So, I use this method to concatenate those two in a single char*:

memcpy(sendBuf, (void*)&sendHeader, sizeof(sendHeader));
memcpy(&sendBuf[sizeof(sendHeader)], readMessage, lengthMessage);

With lengthMessage being the number of characters of the message +1 which is the null termination character.

So, sendBuf it’s defined like this:

char sendBuf[BUFLEN + 1]   // BUF_LEN = 128

And then I put this char* in a queue defined like this:

concurrency::concurrent_queue<char*> IP_in_queue;

So, I want to check if the information it’s correct, so I just check everything:

char* s;
IP_in_queue.try_pop(s);
numbytes = sizeof(s);
// Copy from buf to the header
memcpy( (void*)&readHeader, s, sizeof( IP_PACKET_HEADER_T));
// Copy message part
memcpy( sendedString, &s[sizeof(IP_PACKET_HEADER_T)], numbytes - sizeof(IP_PACKET_HEADER_T));
// Append \0 to the end
sendedString[numbytes - sizeof(IP_PACKET_HEADER_T)] = '\0';

So, before I queue my char*, we know that the size of sendBuf is 129, but when I check the number of bytes after I dequeue it’s way too different, the value of number of bytes it’s 4, but even in that way I get the information right, so I don’t understand that, maybe I missing some important things, but the variable numbytes shouldn’t be at least more?

I hope I made myself clear and maybe someone can explain me this a little bit better.

Thanks

  • 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-11T13:53:27+00:00Added an answer on June 11, 2026 at 1:53 pm

    sizeof does not tell you the length of the string – it tells you the size of the type char*, which on a 32-bit machine is 4 bytes. You want strlen, the number of bytes in the string.

    But even that isn’t what you want. Your structure IP can have nulls in it, so even strlen won’t give you a correct answer. If you put your string first instead of last you can fix that, but I’d consider that kind of a hack. You should add the size explicitly to the start of your message.

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

Sidebar

Related Questions

I've been working on this project for about two weeks now. I don't understand
So I have been working on this project for a short while now. I
Hey all, i've been working on this small project in XNA the goal is
I have been working on a project where I have a Worker class that
I've been working on this project for about a year now. It's a basic
I have been working on a project that displays data in an XML file.
I have been working on a project which is about data copy from one
I have been working on a Java project for a class for a while
I've been working on this for a long time, and I feel very worn
So I’ve been working on this project at work where I’m coding a php

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.