Click to See Complete Forum and Search --> : wchar_t array element comparison


Edward Rush
June 12th, 2002, 02:24 PM
This is in Windows CE/eMbedded VC++:

I need to compare the elements of a wide character array to a delimiter
wchar_t szD = 0x001E;
(szD)
I have a character array of about 80 characters. I have tried many variations using the wcstok function to get my data out of the string. However, the application that I am using is based on a incoming string. It is a barcode scanning app.
Anyway, because of the difficulty in getting correct data from having multple calls to the same function, I have decided to do a byte comparison until I locate the delimiter and do what I have to do with the data prior to the delimiter.
However, nothing I do seems to work.
The string looks like this below with (szD) representing the symbol that delimits the string.

[)> 06(szD)P10289411(szD)Q2916 2JUN067392746340352672(szD)21L14020QQQ(szD)20LPKX61A03(szD)7Q2023GT "

I copy the string to my class, I then proceed to loop through each element of the string either by the character array or a pointer to the character array.

for example:

void PDF417_GM::setm_Variables(PWSTR pBar)
{
long liBLength = wcslen(pBar);

for(int i = 0; i <= liBLength; ++i)
{
//is to display the barcode element
AfxMessageBox((LPCTSTR)&pB[i]);
}

}

But the above does not do what I want it to do. I want only a single character at a time. And the above code is the only thing working for me. It returns a whole string minus the first element at every iteration.

AfxMessageBox((LPCTSTR)pB[i]); <-does not work(pointer)

AfxMessageBox((LPCTSTR)sz_Barcode[i]);<-does not work(wchar_t array)

Any way the above is only a sample.
What I want to do is iterate through every element of the character array until I locate the delimiter.

Thanks

Jami Bradley
June 12th, 2002, 05:15 PM
The reason is displays the entire string, minus the front character(s) is because the nul termination doesn't move. You'll need to either copy it into a message using wsprintf, or just copy the first character into a buffer of two:

wchar_t Msg[2] = { 0, 0 };

Msg[0] = pB[i]; // Msg[1] keeps the nul

AfxMessageBox(Msg);


Jami

Edward Rush
June 13th, 2002, 12:32 PM
I tried your suggestion an it works.

Thanks.

Ed Rush

Stabilus
Gastonia, North Carolina