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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:58:37+00:00 2026-06-18T20:58:37+00:00

So I have the following: char * buffer = (char *) malloc(2*80 + 4);

  • 0

So I have the following:

char * buffer = (char *) malloc(2*80 + 4);
uint32_t networkedRin = htonl(student->rin);

printf("RIN %u\n", student->rin);

//Clear all memory and copy the first last and rin into the new buffer
memset(buffer, '\0', 164);
memcpy(buffer, student->firstname, 80);
memcpy(buffer+80, student->lastname, 80);
memcpy(buffer+160, &networkedRin, 4);

printf("Networked rin: %u\n", networkedRin);

printf("L5: %s %s %u\n", buffer, buffer+80, buffer+160);

and I am very confused because when I do the printing at the end the expected value is the same as Networked rin value printed earlier but it is not, in fact its garbage because it is constantly changing with every run. Now I know I should be using sizeof or whatever but we were told to just use the hard coded value of 4 for uint32 and what not. I’m stuck as to why I’m getting garbage when trying to display the networked rin number from the buffer.

For example I am receiving this output after two runs of the program

RIN 60
Networked rin: 1006632960
L5: loller cats 16375984


RIN 60
Networked rin: 1006632960
L5: loller cats 10260656

I’m sure its something simple but I just can’t see it.

  • 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-18T20:58:38+00:00Added an answer on June 18, 2026 at 8:58 pm

    buffer+160 is not the value you are looking for.
    buffer+160 is a a pointer to your int, not your int itself.

    You must type-cast and de-reference the pointer to see the value you want.

    printf("L5: %s %s %u\n", buffer, buffer+80, *(uint32_t*)(buffer+160));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: #include <string.h> int main(void) { char *buffer = NULL,
i have the following code : int * buffer; buffer = (int *) malloc((320*240)*sizeof(int));
I have the following code: int send_cmd( int sock, char * buffer, int lbuffer
I have a couple of questions related to the following code: char buffer[256]; memset(buffer,0,256);
Suppose I have the following in C++: char buffer[SIZE]; char * ptr = &buffer[SIZE];
Suppose I have a following constructor in C++ class: MyClass::MyClass() { char* buffer =
I have the following code: int ircsocket_print(char *message, ...) { char buffer[512]; int iError;
I have the following code; void* buffer = operator new(100); unsigned char* etherhead =
I have the following code: char stats[109]; /* !LINE UNDER QUESTION! */ sprintf(stats, OBJECTS:\n%u/256\n
gcc 4.4.2 I have the following code: char channels[] = NumberOfChannel = [2]; sscanf(channels,

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.