Click here to Skip to main content
15,886,110 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: printing bitmaps Pin
Roger Allen19-Mar-06 12:24
Roger Allen19-Mar-06 12:24 
AnswerRe: printing bitmaps Pin
Hamid_RT19-Mar-06 17:09
Hamid_RT19-Mar-06 17:09 
QuestionWhere is call for DLL within VisStu 6.0 C++ Pin
Robert Palma Jr.19-Mar-06 7:45
Robert Palma Jr.19-Mar-06 7:45 
AnswerRe: Where is call for DLL within VisStu 6.0 C++ Pin
Richard Andrew x6419-Mar-06 7:55
professionalRichard Andrew x6419-Mar-06 7:55 
GeneralRe: Where is call for DLL within VisStu 6.0 C++ Pin
Robert Palma Jr.19-Mar-06 8:11
Robert Palma Jr.19-Mar-06 8:11 
GeneralRe: Where is call for DLL within VisStu 6.0 C++ Pin
Richard Andrew x6419-Mar-06 8:17
professionalRichard Andrew x6419-Mar-06 8:17 
GeneralRe: Where is call for DLL within VisStu 6.0 C++ Pin
Robert Palma Jr.19-Mar-06 8:28
Robert Palma Jr.19-Mar-06 8:28 
QuestionWhy memcpy not correct! Pin
Hongjun Ge19-Mar-06 7:10
Hongjun Ge19-Mar-06 7:10 
:-OI have a class:
class CTest<br />
{<br />
public:<br />
    char szData1[5];<br />
    char szData2[10];<br />
    char szData3[5];<br />
<br />
    CTest(CString strValue)<br />
    {<br />
        Init();<br />
<br />
        if (strValue.IsEmpty()) {<br />
            return;<br />
        }<br />
<br />
        int nPos = strValue.Find("\n");<br />
        if (nPos != -1) {<br />
            memcpy(szData1, strValue.Left(nPos), sizeof(szData1));<br />
            strValue.Delete(0, nPos + 1);<br />
        } else {<br />
            memcpy(szData1, strValue, sizeof(szData1));<br />
            return;<br />
        }<br />
<br />
        nPos = strValue.Find("\n");<br />
        if (nPos != -1) {<br />
            memcpy(szData2, strValue.Left(nPos), sizeof(szData2));<br />
            strValue.Delete(0, nPos + 1);<br />
        } else {<br />
            memcpy(szData2, strValue, sizeof(szData2));<br />
            return;<br />
        }<br />
<br />
        nPos = strValue.Find("\n");<br />
        if (nPos != -1) {<br />
            memcpy(szData3, strValue.Left(nPos), sizeof(szData3));<br />
            strValue.Delete(0, nPos + 1);<br />
        } else {<br />
            memcpy(szData3, strValue, sizeof(szData3));<br />
            return;<br />
        }<br />
    }<br />
private:<br />
    void Init()<br />
    {<br />
        memset(szData1, 0, sizeof(szData1));<br />
        memset(szData2, 0, sizeof(szData2));<br />
        memset(szData3, 0, sizeof(szData3));<br />
    }<br />
};

I used in MFC application like this
CTest t("1234567890\nabcdefghi\n123456789\n");
TRACE("%s\n", t.szData1);

I got this "12345asdfjpwerpaspo8€gA" that is not my purpose.
Any one can tell why!
Thanks.

Hongjun Ge

-- modified at 2:00 Monday 20th March, 2006

Thanks for all help! I have found solution about this.

class CTest<br />
{<br />
public:<br />
    char szData1[5];<br />
    char szData2[10];<br />
    char szData3[5];<br />
<br />
    CTest(CString strValue)<br />
    {<br />
        Init();<br />
<br />
        if (strValue.IsEmpty()) {<br />
            return;<br />
        }<br />
<br />
        int nPos = strValue.Find("\n");<br />
        if (nPos != -1) {<br />
            memcpy(szData1, strValue.Left(nPos), sizeof(szData1));<br />
            strValue.Delete(0, nPos + 1);<br />
        } else {<br />
            memcpy(szData1, strValue, sizeof(szData1));<br />
            goto Reset;<br />
        }<br />
<br />
        nPos = strValue.Find("\n");<br />
        if (nPos != -1) {<br />
            memcpy(szData2, strValue.Left(nPos), sizeof(szData2));<br />
            strValue.Delete(0, nPos + 1);<br />
        } else {<br />
            memcpy(szData2, strValue, sizeof(szData2));<br />
            goto Reset;<br />
        }<br />
<br />
        nPos = strValue.Find("\n");<br />
        if (nPos != -1) {<br />
            memcpy(szData3, strValue.Left(nPos), sizeof(szData3));<br />
            strValue.Delete(0, nPos + 1);<br />
        } else {<br />
            memcpy(szData3, strValue, sizeof(szData3));<br />
            goto Reset;<br />
        }<br />
Reset:<br />
    szData1[sizeof(szData1) - 1] = '\0';<br />
    szData3[sizeof(szData2) - 1] = '\0';<br />
    szData3[sizeof(szData3) - 1] = '\0';<br />
<br />
    }<br />
private:<br />
    void Init()<br />
    {<br />
        memset(szData1, 0, sizeof(szData1));<br />
        memset(szData2, 0, sizeof(szData2));<br />
        memset(szData3, 0, sizeof(szData3));<br />
    }<br />
};



AnswerRe: Why memcpy not correct! Pin
Richard Andrew x6419-Mar-06 7:26
professionalRichard Andrew x6419-Mar-06 7:26 
AnswerRe: Why memcpy not correct! Pin
Richard Andrew x6419-Mar-06 7:31
professionalRichard Andrew x6419-Mar-06 7:31 
GeneralRe: Why memcpy not correct! Pin
Hongjun Ge19-Mar-06 16:05
Hongjun Ge19-Mar-06 16:05 
AnswerRe: Why memcpy not correct! Pin
Richard Andrew x6419-Mar-06 7:41
professionalRichard Andrew x6419-Mar-06 7:41 
GeneralRe: Why memcpy not correct! Pin
bob1697219-Mar-06 8:04
bob1697219-Mar-06 8:04 
GeneralRe: Why memcpy not correct! Pin
Richard Andrew x6419-Mar-06 8:14
professionalRichard Andrew x6419-Mar-06 8:14 
GeneralRe: Why memcpy not correct! Pin
bob1697219-Mar-06 8:26
bob1697219-Mar-06 8:26 
AnswerRe: Why memcpy not correct! Pin
bob1697219-Mar-06 7:58
bob1697219-Mar-06 7:58 
AnswerRe: Why memcpy not correct! Pin
David Crow19-Mar-06 9:15
David Crow19-Mar-06 9:15 
Questioni want to let white transform into black Pin
lowkey5719-Mar-06 4:16
lowkey5719-Mar-06 4:16 
AnswerAnd what's the problem? Pin
normanS19-Mar-06 18:12
normanS19-Mar-06 18:12 
Questionanyone expert in C++ help me please Pin
omegahawk19-Mar-06 3:47
omegahawk19-Mar-06 3:47 
AnswerRe: anyone expert in C++ help me please Pin
Chris Losinger19-Mar-06 4:17
professionalChris Losinger19-Mar-06 4:17 
QuestionMemory leak detection Pin
Waldermort19-Mar-06 1:41
Waldermort19-Mar-06 1:41 
AnswerRe: Memory leak detection Pin
Joe Woodbury19-Mar-06 11:42
professionalJoe Woodbury19-Mar-06 11:42 
QuestionUnknown message Pin
Irina Tseitlin19-Mar-06 1:16
Irina Tseitlin19-Mar-06 1:16 
AnswerRe: Unknown message Pin
karle19-Mar-06 5:26
karle19-Mar-06 5:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.