Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.
v.c++changing cstring to char array
Name: twend34 Date: May 4, 2006 at 10:32:33 Pacific OS: window CPU/Ram: pentium4 Product: microsoft
Comment:
I want a small code which can change CString to a char array.Or I want how can I assign the string I get from a user through my edit box in a dialog box to a char array to access each letter .please respond
Name: egkenny Date: May 6, 2006 at 05:26:25 Pacific
Reply:
CString str; char a, b, c; char *cstr = new char[20]; char *dstr = new char[20];
str = "Hello World!"; // set initial string data a = str[4]; // get single character at index 4 b = str.GetAt(6); // get single character at index 6 c = 'Z'; str.SetAt(5,c); // set single character at index 5 strcpy(cstr, LPCTSTR (str)); // copy char character array str = "dog & cat"; strcpy(dstr, str); // copy char character array
final result: a = 'o' b = 'W' c = 'Z' str = "dog & cat" cstr = "HelloZWorld!" dstr = "dog & cat"
Summary: It looks like you'll need to declare an array of char then use sprintf to convert the number i into a string before you can use string concatenation. I assume that is in C and not C++. ...
Summary: If you are using C/C++, and the string is not a class, it is _already_ a char array. But if you must copy the string, you can do: char *foo_str=(char*)malloc(strlen(String)+1); strcpy(foo_str,String);...
Summary: first off im using turbo c++ so i cant use the string.h library. I need to take words from a txt file and put them into a char array. i declare the array something like char array[10][15]; im not ce...