strtok_s

Hi everyone,

I am trying to make a function prints every letter that is passed to it, but does so slowly.
Below is the function, but when I call it, it simply prints the whole message string (as it should do as a test at the top of the function). but it does not print the letters of the message string as I expect it to.
I tried working out what was going on by printing the size of the string vector I create while tokenising, and it says the size is 0 (so I am assuming that the actual tokenising is going wrong), can anyonne help? =]

I am calling the function like this:

1
2
3
	
std::string message = "Patcher client loading! Awesome...";
Console(message);



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
void Console(std::string message);
void Console(std::string message)
{
	printf("%s\n", message.c_str());

	char* context	= NULL;
	std::vector<std::string> str_Vector;
	char *pch;
	pch = strtok_s((char *)message.c_str(),"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXZ	,.;:()\"! £$%^&*-_=+<>?/{}[]|'@#~\n", &context);
	while (pch != NULL)
	{
		std::string strData = pch;
		str_Vector.push_back(strData);
		pch = strtok_s(NULL, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXZ	,.;:()\"! £$%^&*-_=+<>?/{}[]|'@#~\n", &context);
	}
	printf("Size %i\n", str_Vector.size());

	for(unsigned int i = 0; i < str_Vector.size(); i++)
	{
		printf("%s", str_Vector.at(i).c_str());
		Sleep(400);
	}
	printf("\n");
}
Hello reborn,

I don't know what you think that strtok_s() is supposed to do but don't use it anyway there're always better approaches to solve your problem like this:

1
2
3
4
5
6
    for(unsigned int i = 0; i < message.size(); i++)
    {
        printf("%c", message[i]);
        Sleep(400);
    }
    printf("\n");
Hi! It is better to send message as a constant reference. And try to use http://www.boost.org/doc/libs/1_41_0/libs/tokenizer/index.html for tokenising.
Topic archived. No new replies allowed.