1

i am actually tryin to convert a csharp code to c... below is the C# code..

CString data = "world is beautiful";    
Byte[] quote = ASCIIEncoding.UTF8.GetBytes(data);

in the above code... it converts the string into bytes..similarily is ther a way that i can convert it using C.. Can any body tell what wud be the quivalent code in C? Please help me guys

Goz
  • 61,365
  • 24
  • 124
  • 204
kiddo
  • 1,596
  • 7
  • 31
  • 60

2 Answers2

3

Well CString is a C++ class so doing it in C is a little unlikely.

But if you wish to get it as a standard multi-byte encoded string then you can do the following

CString data    = "world is beautiful";
CStringA mbStr  = data;
char* bytes     = mbStr.GetString();
Goz
  • 61,365
  • 24
  • 124
  • 204
  • tanx for u reply.. but still its reading it as an string but not as bytes.. does it makes sense – kiddo Oct 30 '09 at 14:31
  • a char array IS an array of bytes. Just because you look in a debugger and it interprets it as a set of characters is neither here nor there. You DO have an array of bytes. – Goz Oct 30 '09 at 15:10
0

In C the char type is defined as one byte in memory. Hence storing your string as a char * would be equivalent to storing a byte array in C#.

Benjamin Dobell
  • 4,042
  • 1
  • 32
  • 44