Solved

String Concat problem, not working

Posted on 2013-06-22
3
353 Views
Last Modified: 2013-06-23
I am trying to concat 9 edit controls. I don't see why this code is not working. Can anyone help me get this working?

    char szCombo1[2], szCombo2[2],szCombo3[2],
         szCombo4[2],szCombo5[2],szCombo6[2],
         szCombo7[2],szCombo8[2],szCombo9[2];
     
    GetDlgItemText(gl_hWnd, IDC_COMBO1, szCombo1, strlen(szCombo1));
    GetDlgItemText(gl_hWnd, IDC_COMBO2, szCombo2, strlen(szCombo2));
    GetDlgItemText(gl_hWnd, IDC_COMBO3, szCombo3, strlen(szCombo3));
    GetDlgItemText(gl_hWnd, IDC_COMBO4, szCombo4, strlen(szCombo4));
    GetDlgItemText(gl_hWnd, IDC_COMBO5, szCombo5, strlen(szCombo5));
    GetDlgItemText(gl_hWnd, IDC_COMBO6, szCombo6, strlen(szCombo6));
    GetDlgItemText(gl_hWnd, IDC_COMBO7, szCombo7, strlen(szCombo7));
    GetDlgItemText(gl_hWnd, IDC_COMBO8, szCombo8, strlen(szCombo8));
    GetDlgItemText(gl_hWnd, IDC_COMBO9, szCombo9, strlen(szCombo9));
              
    std::string strCombo1(szCombo1);
    std::string strCombo2(szCombo2);
    std::string strCombo3(szCombo3);
    std::string strCombo4(szCombo4);
    std::string strCombo5(szCombo5);
    std::string strCombo6(szCombo6);
    std::string strCombo7(szCombo7);
    std::string strCombo8(szCombo8);
    std::string strCombo9(szCombo9);
    std:string strUserCombo;
    strUserCombo = strCombo1+strCombo2+strCombo3+strCombo4+strCombo5+strCombo6+strCombo7+strCombo8+strCombo9;
    MessageBox(NULL,strUserCombo.c_str(),"DEBUG",NULL);

Open in new window


Thanks!
0
Comment
Question by:edvinson
  • 2
3 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 39268181
In the above, 'strlen()' will return 0 or an undefined value, that's why that won't work. You need to provide the actual size of the buffer as the last argument. Are you sure that should be two bytes?
0
 
LVL 1

Author Comment

by:edvinson
ID: 39268385
I am not sure it should be two bytes, I am expecting the user to enter two digits, thats why i chose 2 bytes. should I only use 1? Or something different? What if I dont know how many characters they entered?
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 39268638
If you are expecting two digits, make that at least 3 bytes (the two digits plus the terminating NULL byte). However, a larger buffer won't hurt ;o)
Anyway, 'strlen()' is the wrong way, since it will report the lenght of the string stored in that buffer - and since there is none prior to your call, that's bound to fail.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Getting IP address 8 71
is twain_32.dll cmpatible with windows 10 ? 10 125
Why isn't object file created? 6 41
Installshield for Embarcadero EX 10.1 Berlin 4 18
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now