I have two char variables, m_GPSOffset and m_FileName. When m_GPSOffset has a value assigned to it, say for instance +11:25:30. The first entry of the value, in this case +, is always stored in m_FileName. I am clueless on why this is occurring. Can anyone tell me why this is happening?
Simple CTest class with corresponding CResource class to attempt to demonstrate what you are attempting to do. But in the CResource class I have initialised the char arrays in the constructor and also check that we don't overrun the buffer when we set one of these arrays. Does that help?
CString s = _T( "Hello World" );
std::wcout << static_cast<constwchar_t *>( s ) << std::endl;
std::wcout << "Number of characters is " << s.GetLength() << std::endl;
wcscpy( t, s.GetBuffer( 2 ) );
if ( t == L'H' && t == L'e' ) wcout << "There is no the terminating zero" << std::endl;
As you see when the size of the buffer is equal to or less then the value returned by GetLength then the terminating zero is not present. So the function strcpy has undefined behaviour. I showed you two methods how you can copy a CString object or you can use strncpy function instead of strcpy and append the terminating zero yourself.
Yes, and strcpy_s will check that you don't exceed the buffer size, as I demonstrated above. If the string being copied is 1 char less than you have declared the array into which you are copying all will be fine, but if it is the same or larger an assertion will be thrown.