CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2000
    Location
    North Carolina
    Posts
    66

    wchar_t array element comparison

    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

  2. #2
    Join Date
    Jan 2001
    Location
    Colorado, USA
    Posts
    71
    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:
    Code:
       wchar_t Msg[2] = { 0, 0 };
    
       Msg[0] = pB[i];  // Msg[1] keeps the nul
    
       AfxMessageBox(Msg);
    Jami

  3. #3
    Join Date
    Nov 2000
    Location
    North Carolina
    Posts
    66
    I tried your suggestion an it works.

    Thanks.

    Ed Rush

    Stabilus
    Gastonia, North Carolina

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured