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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:12:10+00:00 2026-06-17T08:12:10+00:00

I am a c++ newbie and just try to write some code to have

  • 0

I am a c++ newbie and just try to write some code to have experiment myself.

Recently I have encountered a problem that I cannot debug.

char acExpReason[128];
char acReason[] = "An error message is information displayed when an unexpected condition occurs, usually on a computer or other device. On modern operating systems.";

memcpy(acExpReason, acReason, sizeof(acExpReason));
std::string strExpReason(acExpReason);

I use VS2005 to add breakpoints to every line to debug.

when it reaches the breakpoint on the second line, the variable name and value info in the Autos is:

  • acReason 0x00f6f78c “ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ” char [147]

  • acExpReason 0x00f6f828 “ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ̺” char [128]

when it reaches the breakpoint on the third line, the variable name and value info in the Autos is:

  • acExpReason 0x00f6f828 “ÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌÌ̺” char [128]

  • acReason 0x00f6f78c “An error message is information displayed when an unexpected condition occurs, usually on a computer or other device. On modern operating systems.” char [147]

when it reaches the breakpoint on the fourth line, the variable name and value info in the Autos is:

  • acExpReason 0x00f6f828 “An error message is information displayed when an unexpected condition occurs, usually on a computer or other device. On modern ÌÌÌÌÌÌÌ̺” char [128]

  • acReason 0x00f6f78c “An error message is information displayed when an unexpected condition occurs, usually on a computer or other device. On modern operating systems.” char [147]

  • strExpReason Bad Ptr

after the last line is executed, the info in Autos is:

  • acExpReason 0x00f6f828 “An error message is information displayed when an unexpected condition occurs, usually on a computer or other device. On modern ÌÌÌÌÌÌÌ̺” char [128]

  • acReason 0x00f6f78c “An error message is information displayed when an unexpected condition occurs, usually on a computer or other device. On modern operating systems.” char [147]

  • strExpReason “An error message is information displayed when an unexpected condition occurs, usually on a computer or other device. On modern ÌÌÌÌÌÌÌ̺”

basically what my code wants to do is just to have a complete line of msg which is stored in acReason[], and also there is a copy of the complete msg in fixed length(here is 128).

but I don’t know why acExpReason and strExpReason(the string version of the acExpReason) will end with some strange characters “ÌÌÌÌÌÌÌ̺” which I don’t want(as I will use this string to compare with other string later).

I tried using memcpy, strcpy, and strncpy and they all ended up having that set of strange characters in the end of the string.

Can anyone help?
Many thanks in advance.

  • 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-17T08:12:11+00:00Added an answer on June 17, 2026 at 8:12 am

    In C all string functions like strcpy and also the constructor for c++’s std::string take char* as a parameter but the char* must be terminated with a byte containing `\0`.

    acExpReason does not have a zero ending it so all the string functions look for the next 0 byte in memory. acReason does have a trailing `\0`. Normal strcpy would work as it also copies the 0 however as @VladLazarenko says the buffer size is too small which will cause all memory to be overwritten.

    To make memcpy work you need to copy one less byte than the buffer and make the last byte of the buffer 0.
    e.g.

    memcpy(acExpReason, acReason, sizeof(acExpReason)-1);
    acReason[sizeof(acExpReason)-1] = 0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some problems with Javascript. In fact, I'm just newbie in that script
Just a quick newbie question here. I have a method that calculates a value
I am a newbie for facebook apps...Just now starting with some basic code got
I am a newbie and just learned that if I define say package my.first.group.here;
Newbie question: I just installed VisualSVN Server and created a repository. I noticed that
As a Wordpress/PHP newbie, I'm confused. When I try to do some things in
I am newbie android programmer. just started by seeing some online tutorials, i decided
Probably a newbie question but I'll ask anyway. Have a multipage form that I
i'm a newbie in XNA just in case. What i try to do is
I am a newbie in Drupal, I just created a module and try to

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.