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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:35:17+00:00 2026-05-14T15:35:17+00:00

I have the following code, m_edit is a MFC CEdit (I know I would

  • 0

I have the following code, m_edit is a MFC CEdit (I know I would never use MFC but project demanded it).

It’s a simple loop, that gets the text from a text edit, converts it to integer after getting the first line, then stores it in m_y vector.

LPTSTR szTemp;
vector<int> m_y;
for(int i = 0; i < m_edit->GetLineCount(); i++){
  szTemp = s_y.GetBuffer(0); 
  m_edit->GetLine(i, szTemp); // get line text store in szTemp
  y = atoi(szTemp);
  m_y.push_back(y);
  szTemp = "";
  y = 0;
 }

IMPORTANT EXAMPLE: So let’s say the CEdit has 6 numbers:

  • 0
  • 5
  • 2
  • 5
  • 18
  • 6

If you use Visual Studio’s debugger you will notice an anomaly!!
Here’s what it shows:

  • y = 0
  • y = 5
  • y = 2
  • y = 5
  • y = 18
  • y = 68

Do you see that? szTemp when inserted into atoi, it returns the number 6, but concatenates the 2nd digit of the last number!!! This is why I did szTemp = “”;, but the problem persists. Also, let’s say the last number was 17 (not 18), then this time debugger would say y = 67, so it is definitely this problem.

However, Visual Studio debugger, when you hover over szTemp during this iteration, it says ‘6’ <— not ’68’ inside szTemp. So somehow atoi is ruining it.

Am I suppose to concatenate a \0 into szTemp before putting it into atoi? How do I solve this easily?

  • 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-14T15:35:18+00:00Added an answer on May 14, 2026 at 3:35 pm

    From the MFC CEdit::GetLine documentation:

    Remarks:
    The copied line does not contain a null-termination character.

    So you need to pay attention to GetLine‘s return value to determine how many bytes were copied into the buffer and then add your own NUL-terminator.

    Also, I would recommend that you pass in the buffer size to make sure you don’t have a potential buffer overflow.

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

Sidebar

Related Questions

I'm trying to use opengl in C#. I have following code which fails with
I have the following Clojure code and I'm not sure why it's not working:
I have the following code, I'm trying to get a table with 4 columns
I'm using php and I have the following code to convert an absolute path
In every form we derive from FormBaseControl , we have the following code. I'm
I have the following html.erb code that I'm looking to move to Haml: <span
I'm using the following code to have a non-JS navigation: <ol id=navigation> <li id=home><a
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following Code Block Which I tried to optimize in the Optimized section
I have the following code in a web.config file of the default IIS site.

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.