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

  • Home
  • SEARCH
  • 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 6641793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:51:10+00:00 2026-05-25T23:51:10+00:00

I am trying to take two strings (message1, message2), assign str1 to message1 if

  • 0

I am trying to

  • take two strings (message1, message2),
  • assign str1 to message1 if message1 and message2 are empty,
  • assign str2 to message2 if it is empty and message1 is full,
  • and save message 2 over message 1 and put message2 == message3 if both message1 and message2 were full.

I get weird results as shown. But memcpy is not working. (I know it’s my fault somehow.)

input

message1: ffW
message 2: a
message 3 (2 writes over 1, 3 writes over 2): bbb

MESSAGE 1a: ffW 
MESSAGE 2a: a_W 
MESSAGE 1ab: a_W 
MESSAGE 2ab: a_W 
MESSAGE 1b: a_W 
MESSAGE 2b: bbb 

next one:

INPUT:
message1: a
message2: abcde
message3: abcdefg

MESSAGE 1a: a�� 
MESSAGE 2a: abcde 
MESSAGE 1ab: abcd 
MESSAGE 2ab: abcde 
MESSAGE 1b: abcd 
MESSAGE 2b: abcdefg 

.

    if (message1[0] == '\0')
    {
        memcpy(message1, echoBuffer, sizeof echoBuffer);
        fprintf(stderr, "MESSAGE 1: %s \n", message1);
    }
    else if (message1[0] != '\0' && message2[0] == '\0')
    {
        memcpy(message2, echoBuffer, sizeof echoBuffer);
        fprintf(stderr, "MESSAGE 2: %s \n", message2);
    }
    else if (message1[0] != '\0' && message2[0] != '\0')
    {
        fprintf(stderr, "MESSAGE 1a: %s \n", message1);
        fprintf(stderr, "MESSAGE 2a: %s \n", message2);
        memcpy(message1, message2, sizeof message2);
        fprintf(stderr, "MESSAGE 1ab: %s \n", message1);
        fprintf(stderr, "MESSAGE 2ab: %s \n", message2);
        memcpy(message2, echoBuffer, sizeof echoBuffer);
        fprintf(stderr, "MESSAGE 1b: %s \n", message1);
        fprintf(stderr, "MESSAGE 2b: %s \n", message2);
    }
}

Does anybody know what is wrong? This problem has been plaguing me.

I think the messages and echoBuffer are all 100 characters in size.

  • 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-25T23:51:10+00:00Added an answer on May 25, 2026 at 11:51 pm

    Is there a particular reason for using memcpy? I believe that strcpy(char* dest, char* source) would be easier to use. Maybe it could fix your problem

    You must include string.h in order to use it

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

Sidebar

Related Questions

I'm trying to take one group and put it in two different columns. I
I'm trying to take two strings and print them out in alphabetical order. For
trying to take this content: <div class=content>one,two,three</div> <div class=content>four,five,six</div> <div class=content>seven,eight,nine</div> and .split and
Im trying to take a link either when clicked or hover over be able
In Javascript, I am trying to take a full name (First, Middle, and Last)
I'm trying to write a method that will take in two Queues (pre-sorted Linked
For an assesment in C i have to take two files with strings within
I am trying to take a two-tiered foreach which outputs an xml - and
Trying to take a string of tags and only save the first 10 that
Possible Duplicate: Common elements in two lists I am trying to take 2 lists

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.