cstring

how do I parse a ',' separated char string using c?

What is the easiest way of parsing a comma separated list, where there can be zero elements between each token. The cstring could look like 1, 3, 4, 5, 6, 7, 8, .... But could also look like , , , , , , , , , ... I've tried something like: char *original = "1, 3, 4, 5, 6, 7, 8, ...." char *tok = strtok(original," ,") while(tok!=NU...

CString vs wstring

I have an MFC application in C++ that uses std::string and std::wstring, and frequently casts from one to the other, and a whole lot of other nonsense. I need to standardize everything to a single format, so I was wondering if I should go with CString or std::wstring. In the application, I'll need to generate strings from a string tabl...

C++ comparing c string problem

I have written the following code which will does not work but the second snippet will when I change it. int main( int argc, char *argv[] ) { if( argv[ 1 ] == "-i" ) //This is what does not work //Do Something } But if I write the code like so this will work. int main( int argc, char *argv[] ) { string opti = "-i"; if( ...

How to create a CString from an array of chars?

Hello! Need to log the content of buf using the LogMethod() below the problem is that LogMethos only accepts a "Const CString&" char buf[1024]; strcpy(buf, cErrorMsg); // need to pass to LogMethod "buf" how do i do that? log.LogMethod(const CString &); Thans Rev Reversed ...

Need to write to a string constant, how do I work around this?

I have the following code: int main() { char *sPPhrase[51]; /* Input */ printf("Enter string (max. 50 chars):\n"); fflush(stdout); /* Works around an annoying Eclipse bug that fails to display the output from the printf command */ scanf("%s", *sPPhrase); /* Won't work */ /* More code g...

Initializing a Char*[]

Question is in the title, how do I initialize a char*[] and give values to it in C++, thank you. ...

Why is my char* writable and sometimes read only in C++

I have had really big problems understand the char* lately. Let's say I made a recursive function to revert a char* but depending on how I initialize it I get some access violations, and in my C++ primer I didn't find anything giving me the right path to understand so I am seeking your help. CASE 1 First case where I got access violatio...

unmanaged c++ dll called from c#, crashes when CString used in dll

Hello Most excellent Stackoverflowians Using visual studio 2008 Team System, I have a c++ dll (mfc statically linked regular dll) which has a simple function extern "C" __declspec(dllexport) int MyExportedFunction( ) { AFX_MANAGE_STATE(AfxGetStaticModuleState( )) CString tempString ; .... } The DLLImport from the c# applica...

c++ , getting the length of an array using strlen in g++ compiler

could someone explain why i am getting this error when i am compiling the source using following g++ compiler #include <cstdio> #include <string> using namespace std; int main() { char source_language[50]; scanf("%16s\n",source_language); int length = sizeof(source_language); int sizeofchar = strlen(source_language)...

Initializing an array of cstring inside a function call

How come I can do this: char sXSongs[20][30] = {"Song 1", "Song 2 (w/Blur)", "The End (It's Not Here Yet)"}; addAlbum(&list, "The Beatles", "Some Famous CD", 1960, sXSongs); But not this: addAlbum(&list, "The Beatles", "Some Famous CD", 1960, {"Song 1", "Song 2 (w/Blur)", "The End (It's Not Here Yet)"}); Is it impossible to initial...

Why can't I initialize an array of cstrings like this?

char sXSongBuffer[20][30]; sXSongBuffer = {"Thriller", "Don't Stop Till You Get Enough", "Billy Jean"}; Why does this return the error expected expression before ‘{’ token? The reason I want to initialize my array like this is so that I can change its contents like this later: sXSongBuffer = {"New Song", "More Music From Me"}; ...

Can I assume that two-dimensional arrays are initialized properly like this?

When I declare a two-dimensional array like this: char myArray[20][30] = {"ABC", "Is Easy As One Two Three"}; Can I assume that all other chars in this array are now set to \000? ...

UTF-8, CString and CFile? (C++, MFC)

Hello! I'm currently working on a MFC program that specifically has to work with UTF-8. At some point, I have to write UTF-8 data into a file; to do that, I'm using CFiles and CStrings. When I get to write utf-8 (russian characters, to be more precise) data into a file, the output looks like Ðàñïå÷àòàíî: Ñèñòåìà Ïðîèçâîäñòâî and et...

What if I don't call ReleaseBuffer after GetBuffer?

From http://stackoverflow.com/questions/559483/cstring-to-char, ReleaseBuffer() must be used after GetBuffer(). But why? What will happen if I don't use ReleaseBuffer after GetBuffer()? Can somebody show me an example? Thanks. ...

file doesn't open, running outside of debugger results in seg fault (c++)

Hello (and thanks in advance) I'm in a bit of a quandry, I cant seem to figure out why I'm seg faulting. A couple of notes: It's for a course -- and sadly I am required to use use C-strings instead of std::string. Please dont fix my code (I wont learn that way and I will keep bugging you). please just point out the flaws in my ...

How to overwrite an array of char pointers with a larger list of char pointers?

My function is being passed a struct containing, among other things, a NULL terminated array of pointers to words making up a command with arguments. I'm performing a glob match on the list of arguments, to expand them into a full list of files, then I want to replace the passed argument array with the new expanded one. The globbing is...

Convert CString array to System::String

Hi, I want to convert CString array to managed code ot send it to C#. For normal CString i did like this, CString menu = "MENU"; String ^ msg = gcnew String(menu); Globals1::gwtoolbar->Add(msg); But now i want to send array of string.i dont know how to do for CString array. When i gave like this it shows error CString menu[10]; Stri...

Cannot convert CString to BYTE array

I need to convert CString to BYTE array. I don't know why, but everything that I found in internet does not work :( For example, I have CString str = _T("string"); I've been trying so 1) BYTE *pbBuffer = (BYTE*)(LPCTSTR)str; 2) BYTE *pbBuffer = new BYTE[str.GetLength()+1]; memcpy(pbBuffer, (VOID*)(LPCTSTR)StrRegID, str.GetLength(...

compare function for dates

I have struct as: struct stored { char *dates; // 12/May/2010, 10/Jun/2010 etc.. }; // const struct stored structs[] = {{"12/May/2010"}, {"12/May/2011"}, {"21/May/2009"}, {"13/May/2011"}, {"10/May/2011"}, {"19/May/2011"}}; What I want to do is to sort struct 'stored' by store...

How can I hash a string to an int using c++?

I have to write my own hash function. If I wanted to just make the simple hash function that maps each letter in the string to a numerical value (i.e. a=1, b=2, c=3, ...), is there a way I can perform this hash on a string without having to first convert it to a c-string to look at each individual char? Is there a more efficient way of h...