I am working on a project that requires me to recive data from a network application. After I recive the data I'm suppose to break it up. Now I know of a way to sorta do that by using "tokens" and strtok (if you don't know strok breaks up a string by delminating character i.e. \n ). My problem is that I need to do it twice. Once for "\n" and once for "\t", but my program crashes when I use strtok a second time. For example:

tokenPtr = strtok (m_pBuf , "\n");
	while ( tokenPtr != NULL )
	{
		temp[i] = tokenPtr;
		tokenPtr = strtok(NULL, "\n");
		i++;
	}

This works, but doesn't give to resluts needed. I need to break it further up, however:

tokenPtr = strtok (m_pBuf , "\n");
	while ( tokenPtr != NULL )
	{
		temp[i] = tokenPtr;
		tokenPtr = strtok(NULL, "\n");
		i++;
	}
	while ( count <= i )
	{
		tokenPtr = strtok (temp[count] , "\t");
		while ( tokenPtr != NULL )
		{
			temp2[j] = tokenPtr;
			tokenPtr = strtok(NULL, "\t");
			j++;
		}
		count++;
		tokenPtr = "";
	}

crashes the program.
Any ideas on how to work this out?

why can't you just strtok(str, "\t\n") ?

WOW!!! Thank you!!! That worked exactly like I wanted!! :) Thank you so much. (In answer to your question, I didn't know I could do that and make it work right. It doesn't seem like it would, but it does!) Thank you again!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.