07-27-2012 03:29 PM
I would like to use CVI to accomplish the same thing as the LabView String to Byte Array Function does. Is there a way to do this?
07-27-2012 04:26 PM
Unless the LV function does something not obvious from it's name, you don't need to do anything in C. A string is already a byte array. Just index whatever byte you want:
char str[10] = "Hello World";
printf("%c%c", str[0],str[6]);// will output HW
07-27-2012 05:15 PM
Alright, but what if your string consists of characters such as: µ?
Quinn
07-27-2012 06:04 PM - edited 07-27-2012 06:05 PM
That's still just a single byte character so it works perfectly fine. Are you concerned about using multi-byte characters?
I looked up LabView's documentation and it looks like String To Byte Array just returns an array of unsigned bytes which is essentially the same thing as a string in C and it doesn't appear to handle multi-byte chars.
07-30-2012 10:11 AM
Yes.Thank you. I meant to put something like this one: ž.
Do you know od any way to handle multi-byte characters in LabWindows?
Quinn
07-30-2012 10:25 AM
CVI has a bunch of functions for handling multi-byte characters. I'd suggest taking a look at CmbIsLeadByte() which determines whether the byte you're looking at is the leadbyte of a multibyte character and theCmbStrInc()/CmbStrDec() functions which will move a pointer to either the next or previous character in a string. You could easily write your own String to MultiByte array function using those functions.
I'd suggest reading Programming for Multibyte Character Sets in LabWindows/CVI for a more detailed explanation of all the multi-byte functions CVI offers and how to use them.
07-30-2012 10:31 AM
Thank you very much!
I just have one other things I am confused about. You said that µ is still a single byte character but most online ASCII to Binary converters tell me that its binary conversion is: 11000010 10110101. Is this incorrect?
07-30-2012 10:52 AM
The second byte, 10110101 is equivalent to 181, which is the location of µ in the extended ASCII table according to ISO Latin-1 (there are different 8-bit ASCII variations). I'm guessing that those bit values are the location of µ in Unicode, although in CVI (and many other text editors) that character can be found in standard 8-bit ASCII as well.
You can see the full Latin-1 table here.
07-30-2012 11:04 AM
Thank you very much! You have been extremely helpful.
Quinn