Click here to Skip to main content
16,020,182 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: windowless shockwaveflash control doesn't work properly individually Pin
followait22-Feb-11 14:20
followait22-Feb-11 14:20 
QuestionProblem in Excel Automation. Pin
Le@rner21-Feb-11 21:41
Le@rner21-Feb-11 21:41 
AnswerRe: Problem in Excel Automation. Pin
Niklas L21-Feb-11 22:18
Niklas L21-Feb-11 22:18 
QuestionRichEdit and ITextHost scrollbar Pin
Tangwang21-Feb-11 17:26
Tangwang21-Feb-11 17:26 
QuestionGetting File Path of the Current Program [modified] [SOLVED] Pin
AmbiguousName21-Feb-11 7:09
AmbiguousName21-Feb-11 7:09 
AnswerRe: Getting File Path of the Current Program Pin
Hans Dietrich21-Feb-11 7:19
mentorHans Dietrich21-Feb-11 7:19 
AnswerRe: Getting File Path of the Current Program [modified] [SOLVED] Pin
David Crow21-Feb-11 11:05
David Crow21-Feb-11 11:05 
QuestionStripping new line problem Pin
csrss21-Feb-11 4:26
csrss21-Feb-11 4:26 
OK, here is a func i wrote for stripping new lines:

wchar_t * StripNL(IN wchar_t *buff)
	{
		int len = wcslen(buff);
		wchar_t *temp = (wchar_t *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 
			sizeof(wchar_t *) * len + 1);
		int x = 0;

		for (int i = 0; i < len; i++)
		{
			if(buff[i] != '\n' && buff[i] != '\r\n')
			{
				temp[x] = buff[i];
				x++;
			}
		}
		temp = (wchar_t *)HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, 
			temp, sizeof(wchar_t *) * wcslen(temp) + 1);
		return temp;
	}


Here is some dirty array constructor function, it returns array where strings including new lines:

wchar_t **sss(int &lll)
{
	wchar_t *Arr[] = {L"\r\ntest test\n\n", L"test\r\n\r\n so be it\n\n"};
	for (int i = 0; i < (sizeof(Arr) / sizeof(wchar_t *)); i++)
	{
		lll++;
	}
	return Arr;
}


Now i am trying to strip new lines from array's strings like that:

int elems = 0;
wchar_t **Arr = sss(elems);
for (int i = 0; i < elems; i++)
{
	wprintf(L"elems: %s, len = %d\r\n", StripNL(Arr[i]), wcslen(Arr[i]));
}


Now this behaves completely crazy. WHile it should output:

elems: test test, len = some len
elems: test so be it, len = some len

it prints this:

test test, len = some len
so be it, len = some len

And then app crashes. So it strips something that is shouldnt. It looks like memory gets overwritten somewhere, but i cannot see where exactly?
Thanks
011011010110000101100011011010000110100101101110
0110010101110011

AnswerRe: Stripping new line problem Pin
Maximilien21-Feb-11 4:48
Maximilien21-Feb-11 4:48 
GeneralRe: Stripping new line problem Pin
csrss21-Feb-11 4:53
csrss21-Feb-11 4:53 
AnswerRe: Stripping new line problem Pin
csrss21-Feb-11 6:17
csrss21-Feb-11 6:17 
AnswerRe: Stripping new line problem Pin
User 742933821-Feb-11 19:48
professionalUser 742933821-Feb-11 19:48 
GeneralRe: Stripping new line problem Pin
csrss21-Feb-11 23:32
csrss21-Feb-11 23:32 
AnswerRe: Stripping new line problem Pin
Niklas L21-Feb-11 20:05
Niklas L21-Feb-11 20:05 
GeneralRe: Stripping new line problem Pin
csrss21-Feb-11 23:42
csrss21-Feb-11 23:42 
QuestionHow to capture the desktop image behind my main window Pin
Tcpip200521-Feb-11 1:28
Tcpip200521-Feb-11 1:28 
AnswerRe: How to capture the desktop image behind my main window Pin
Hans Dietrich21-Feb-11 1:38
mentorHans Dietrich21-Feb-11 1:38 
GeneralRe: How to capture the desktop image behind my main window Pin
Tcpip200521-Feb-11 14:20
Tcpip200521-Feb-11 14:20 
AnswerRe: How to capture the desktop image behind my main window Pin
_AnsHUMAN_ 21-Feb-11 1:44
_AnsHUMAN_ 21-Feb-11 1:44 
AnswerRe: How to capture the desktop image behind my main window Pin
goorley24-Feb-11 21:03
goorley24-Feb-11 21:03 
QuestionWM_COMMAND is not getiing fired Pin
VC_RYK20-Feb-11 23:38
VC_RYK20-Feb-11 23:38 
AnswerRe: WM_COMMAND is not getiing fired Pin
Andrew Brock20-Feb-11 23:57
Andrew Brock20-Feb-11 23:57 
QuestionMessageBox vs AfxMessageBox Pin
Jens Joseph20-Feb-11 23:13
Jens Joseph20-Feb-11 23:13 
AnswerRe: MessageBox vs AfxMessageBox Pin
_AnsHUMAN_ 20-Feb-11 23:50
_AnsHUMAN_ 20-Feb-11 23:50 
AnswerRe: MessageBox vs AfxMessageBox Pin
Hans Dietrich20-Feb-11 23:59
mentorHans Dietrich20-Feb-11 23:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.