Click here to Skip to main content
15,867,453 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
for example, take the char array holding ascii value "656667", the int conversion i'm looking for would change those vlaue to a single character  with "ABC".

any help would be very much appreciated.


What I have tried:

    CString msg;
char nbuf[10] = {65,67,66};
for (int i = 0; i < 10; i++) {
    msg.Format(L"%c", (BYTE)nbuf[i]);

    m_asciiresult.SetWindowTextW(msg);
}
Posted
Updated 15-Jun-20 20:11pm
Comments
Richard MacCutchan 15-Jun-20 9:13am    
Why would you do that instead of:
wchar_t nbuf[] = L"ABC";

// or even
CString msg = L"ABC";
Member 14837073 15-Jun-20 9:33am    
I hope you understand my questions,

Here i am talking about conversions ...
for exmple
char nbuf[10] = {67,68,69,70,70,72};
msg.Format(L"%c", (BYTE)nbuf[0]);

m_asciiresult.SetWindowTextW(msg);
i am geting output for this "C" but i want the output something like "CDEF"..but i doing correct or wrong above code but i want help
Member 14837073 15-Jun-20 9:36am    
CString msg;
wchar_t nbuf[] = L"ABC";
msg.Format(L"%d", nbuf);
m_asciiresult.SetWindowTextW(msg);
even i try this one it was like character to change the integer but this also i did not get proper out i am geting dummy value ....

Your question is not clear at all. If you want to convert a string to an integer you can use the function atoi.
Quote:
the int conversion i'm looking for would change those vlaue to a single character with "ABC".
I have no idea what that sentence means.

I think you need to clarify for yourself (and us) whether you are really converting data or just formatting it for display? Those are usually two different things. It appears you are adjusting the format it is displayed in but that is difficult to determine.

You should also review the answer I gave the last time you asked a question that was quite similar to this one. It appeared in the list of previous questions in the right-hand column of this page.
 
Share this answer
 
v3
Comments
Member 14837073 16-Jun-20 1:30am    
i am sorry i am not able to make understand you guys , i am new in developers filed ,
lets again i will try to explain , for Example

CString msg;
char nbuf = 67

msg.Format(L"%c", (BYTE)nbuf);

m_asciiresult.SetWindowTextW(msg);
above the program i am geting output C (67 ascii value character is "C") , Now what i want is array format . the ascci value are in ,
char nbuf[]={67,68,69} ,this i want character 67=C,68=D,69=E ,it means the want output is "CDE" either above the program i doing correct or wrong please make it help ,i hope i make you understand ...thank you
What's wrong with
C++
char nbuf[] = {65, 67, 66, '\0'};
CString msg(nbuf)
m_asciiresult.SetWindowText(msg);

?


[update]
Quote:
const unsigned char nbuf[] = { 'A', 'B', '\0', '\0', 'C', 'd', 'e', 'f' };

above the programs , vice virsa ...
I am trying with same way i didnt get if any changes let me know

Expecting output will be "65 66 0 0 67 100 101 102"


You may iteratively augment a CString object using the CString::Format[^] method, not terribly efficient, but it should work, e.g. (not tested)
C++
CString msg;
for (size_t n=0; n < sizeof(nbuf); ++n)
{
  CString s;
  s.Format(_T("%u "), (unsigned) nbuf[n]); 
  msg += s; 
}

[/update]
 
Share this answer
 
v4
Comments
Member 14837073 16-Jun-20 2:22am    
Thank you soo much its works ,this just demo programs this way i need implement in serial monitoring ,thanks once again
Member 14837073 16-Jun-20 2:27am    
const unsigned char nbuf[] = { 'A', 'B', '\0', '\0', 'C', 'd', 'e', 'f' };

above the programs , vice virsa ...
I am trying with same way i didnt get if any changes let me know

Expecting output will be "65 66 0 0 67 100 101 102"
CPallini 16-Jun-20 2:53am    
Please, see my updated solution.
Member 14837073 16-Jun-20 4:26am    
no operator "+=" matches these operands
CPallini 16-Jun-20 4:49am    
I've updated it again. Hope this time will work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900