Click here to Skip to main content
15,886,199 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
Ok, replying to my own thread, like Richard MacCutchan pointed out, in such case wcstok cannot be used. Here is working example.


#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, *nexttok;
	int i;
	wchar_t *stuff = test();
	t = wcstok_s(stuff, L",", &nexttok);
	for(i = 0; t; t = wcstok_s(NULL, L",", &nexttok), i++)
	{
		wprintf(L"::%s\n", t);
		wchar_t *get = lolz(t);
		wchar_t *t2, *nexttok2;
		int i2;
		t2 = wcstok_s(get, L",", &nexttok2);
		for(i2 = 0; t2; t2 = wcstok_s(NULL, L",", &nexttok2), i2++)
		{
			wprintf(L":%s\n", t2);
		}
		wprintf(L"End for: %s [%d]\n\n", t, i);
	}
	return 0;
}

011011010110000101100011011010000110100101101110
0110010101110011

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 
AnswerRe: Thread Context Switch : Thread which do nothing takes more time to switch Pin
User 742933813-Jan-11 0:20
professionalUser 742933813-Jan-11 0:20 
AnswerRe: Thread Context Switch : Thread which do nothing takes more time to switch Pin
Luc Pattyn13-Jan-11 1:52
sitebuilderLuc Pattyn13-Jan-11 1:52 
AnswerRe: Thread Context Switch : Thread which do nothing takes more time to switch Pin
rod naR18-Jan-11 17:27
rod naR18-Jan-11 17:27 
QuestionDownload file using CInternetSession [modified] Pin
john563212-Jan-11 21:37
john563212-Jan-11 21:37 
AnswerRe: Download file using CInternetSession Pin
KingsGambit12-Jan-11 22:07
KingsGambit12-Jan-11 22:07 
AnswerRe: Download file using CInternetSession Pin
Richard MacCutchan12-Jan-11 22:18
mveRichard MacCutchan12-Jan-11 22:18 
GeneralRe: Download file using CInternetSession Pin
john563212-Jan-11 22:39
john563212-Jan-11 22:39 
GeneralRe: Download file using CInternetSession Pin
Richard MacCutchan12-Jan-11 23:49
mveRichard MacCutchan12-Jan-11 23:49 
GeneralRe: Download file using CInternetSession Pin
john563213-Jan-11 0:05
john563213-Jan-11 0:05 
GeneralRe: Download file using CInternetSession Pin
Richard MacCutchan13-Jan-11 0:57
mveRichard MacCutchan13-Jan-11 0:57 
AnswerRe: Download file using CInternetSession Pin
Cool_Dev12-Jan-11 23:49
Cool_Dev12-Jan-11 23:49 
Questionhow to create dynamically popupmenu? Pin
yogish29312-Jan-11 21:11
yogish29312-Jan-11 21:11 
QuestionRe: how to create dynamically popupmenu? Pin
CPallini12-Jan-11 21:28
mveCPallini12-Jan-11 21:28 
AnswerRe: how to create dynamically popupmenu? Pin
Cedric Moonen12-Jan-11 21:35
Cedric Moonen12-Jan-11 21:35 

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.