Click here to Skip to main content
15,884,388 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionIsalpha Function Issue. Pin
Mike Certini13-Jan-11 18:00
Mike Certini13-Jan-11 18:00 
AnswerRe: Isalpha Function Issue. Pin
Cool_Dev13-Jan-11 18:11
Cool_Dev13-Jan-11 18:11 
GeneralRe: Isalpha Function Issue. Pin
Andrew Brock13-Jan-11 18:15
Andrew Brock13-Jan-11 18:15 
GeneralRe: Isalpha Function Issue. Pin
Mike Certini13-Jan-11 18:28
Mike Certini13-Jan-11 18:28 
AnswerRe: Isalpha Function Issue. Pin
Luc Pattyn14-Jan-11 0:56
sitebuilderLuc Pattyn14-Jan-11 0:56 
GeneralRe: Isalpha Function Issue. Pin
Mike Certini13-Jan-11 18:28
Mike Certini13-Jan-11 18:28 
AnswerRe: Isalpha Function Issue. Pin
Richard MacCutchan13-Jan-11 22:00
mveRichard MacCutchan13-Jan-11 22:00 
Questionwcstok [modified] Pin
csrss13-Jan-11 2:40
csrss13-Jan-11 2:40 
Here is a sample code which works just fine:

#include <stdio.h>
#include <windows.h>
#define malloc(s) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, s)
#define free(m) HeapFree(GetProcessHeap(), 0, m)
#pragma warning(disable: 4996)

wchar_t *test()
{
	wchar_t aaa[] = L"aaaa,bbbb,cccc,dddd";
	static wchar_t *lol = (wchar_t *)malloc(sizeof(wchar_t *) * wcslen(aaa) + 1);
	wcscpy(lol, aaa);
	return lol;
}

int main(int argc, char **argv)
{
	wchar_t *t;
	int i;
	wchar_t *stuff = test();
	t = wcstok(stuff, L",");
        for(i = 0; t; t = wcstok(NULL, L","), i++)
	{
		wprintf(L"::%s\n", t);
        }
return 0
}



This prints
::aaaa
::bbbb
::cccc
::dddd

Now, here is sample code which just dont work and i got no idea why. Its a wcstok inside of wcstok loop.

#include <windows.h>
#include <stdio.h>
#define malloc(s) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, s)

#define free(m) HeapFree(GetProcessHeap(), 0, m)

#pragma warning(disable: 4996)

wchar_t *test()
{
	wchar_t aaa[] = L"aaaa,bbbb,cccc,dddd";
	static wchar_t *lol = (wchar_t *)malloc(sizeof(wchar_t *) * wcslen(aaa) + 1);
	wcscpy(lol, aaa);
	return lol;
}

wchar_t *lolz(wchar_t *lol)
{
	int i = 2;
	static wchar_t *stuff = (wchar_t *)malloc(sizeof(wchar_t *) * (wcslen(lol) + MAX_PATH)*i);
	wcscpy(stuff, L" ");
	while(i > 0)
	{
		wcscat(stuff, lol);
		wcscat(stuff, L",");
		i--;
	}
	return stuff;
}

int main(int argc, char **argv)
{
	wchar_t *t;
	int i;
	wchar_t *stuff = test();
	t = wcstok(stuff, L",");
	for(i = 0; t; t = wcstok(NULL, L","), i++)
	{
		wprintf(L"::%s\n", t);
		wchar_t *get = lolz(t);
		wchar_t *t2;
		int i2;
		t2 = wcstok(get, L",");
		for(i2 = 0; t2; t2 = wcstok(NULL, L","), i2++)
		{
			wprintf(L":%s\n", t2);
		}
		wprintf(L"End for: %s [%d]\n\n", t, i);
	}
	
	return 0;
}


this should print:
::aaaa
:aaaa
:aaaa
end for aaaa
::bbbb
:bbbb
:bbbb
end for bbbb

You can see from the code, like, for each main tokens it should get subtokens, but it prints only:
::aaaa
:aaaa
:aaaa
end for aaaa

and thats it. Why? thanks
011011010110000101100011011010000110100101101110
0110010101110011
modified on Thursday, January 13, 2011 10:19 AM

AnswerRe: wcstok Pin
Cedric Moonen13-Jan-11 2:53
Cedric Moonen13-Jan-11 2:53 
GeneralRe: wcstok Pin
csrss13-Jan-11 3:20
csrss13-Jan-11 3:20 
GeneralRe: wcstok Pin
Luc Pattyn13-Jan-11 3:26
sitebuilderLuc Pattyn13-Jan-11 3:26 
GeneralRe: wcstok Pin
csrss13-Jan-11 3:29
csrss13-Jan-11 3:29 
GeneralRe: wcstok Pin
Luc Pattyn13-Jan-11 3:40
sitebuilderLuc Pattyn13-Jan-11 3:40 
GeneralRe: wcstok Pin
csrss13-Jan-11 4:04
csrss13-Jan-11 4:04 
QuestionRe: wcstok Pin
Luc Pattyn13-Jan-11 4:14
sitebuilderLuc Pattyn13-Jan-11 4:14 
AnswerRe: wcstok Pin
csrss13-Jan-11 4:24
csrss13-Jan-11 4:24 
AnswerRe: wcstok Pin
Luc Pattyn13-Jan-11 6:51
sitebuilderLuc Pattyn13-Jan-11 6:51 
GeneralRe: wcstok Pin
Cedric Moonen13-Jan-11 3:44
Cedric Moonen13-Jan-11 3:44 
AnswerRe: wcstok Pin
Richard MacCutchan13-Jan-11 2:58
mveRichard MacCutchan13-Jan-11 2:58 
GeneralRe: wcstok Pin
csrss13-Jan-11 3:25
csrss13-Jan-11 3:25 
GeneralRe: wcstok Pin
Richard MacCutchan13-Jan-11 4:10
mveRichard MacCutchan13-Jan-11 4:10 
AnswerRe: wcstok Pin
csrss13-Jan-11 4:28
csrss13-Jan-11 4:28 
QuestionRegistry Reading problem in Windows 7 Pin
Debojyoti Majumder13-Jan-11 0:30
Debojyoti Majumder13-Jan-11 0:30 
AnswerRe: Registry Reading problem in Windows 7 Pin
Madhu Nair13-Jan-11 1:05
Madhu Nair13-Jan-11 1:05 
QuestionThread Context Switch : Thread which do nothing takes more time to switch Pin
pandit8412-Jan-11 23:12
pandit8412-Jan-11 23:12 

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.