Hello

char **pOutData; /* Output results */
char *ptoken

I have a pointer which contains the following
hdjhasdjkhasd;stephenjohnson;647823463;dhasdjhaj

I want to work through and get out just stephenjohnson

I have the following so far, which does not work....any help?

for ( size = 0; size < b2b_data_drill_nNoSelect; size++ )  
{
        if (size == 1 )
        {
	ptoken = strtok(pOutData, ";" );

	while( ptoken != NULL )
	{
	       printf ("Results 2nd:%s\n", pOutData[size] );	
	       printf ("ptoken:%s\n", ptoken );	
	       ptoken = strtok(NULL, ";" );

	}
       }
}

pOutData appears to be a pointer to a pointer or a 2d array of strings, like argv parameter to main() In either event line 5 can not work because strtok() only works with 1d character arrays. pOutData needs to be a pointer that is declared similar to the way you declared pToken

Thanks for the reply

The issue i have is i cannot change pOutData due to it being part of some software we are linking too. So i have to make something work around it...any ideas?

Im really stuck here

I would copy the string into some local buffer because strtok() will replace the ; with null characters, which destroys the original string.

char temp[255];
strcpy(temp,*pOutData);
pToke = strtok(temp,",");
// rest of program here

mmmm still an issue as

printf ("Results 2nd:%s\n", pOutData );

Based on the above printf, i cannot just do a simple strcpy into temp, due to size being included can i?

ah it is working, except at the end the program is bombing out

for ( size = 0; size < b2b_data_drill_nNoSelect; size++ )  
{

      if (size == 1 )
      {
	strcpy(temp,pOutData[size]);
	//printf("Temp = %s\n", temp);
	ptoken = strtok(temp, ";" );
	while( ptoken != NULL )
	{
   	     printf ("Results 2nd:%s\n", pOutData[size] );	
  	     printf ("ptoken:%s\n", ptoken );	
	     ptoken = strtok(NULL, ";" );
	}
       }			
							
				
}

any ideas?

>>except at the end the program is bombing out
Don't know -- probably something else in your program. Did you declare temp variable big enough to hold all the characters in that string ?

>>if (size == 1 )
Why that condition? Just delete the loop and do it like this, unless of course there is other code within that loop that you haven't posted.

strcpy(temp,pOutData[1]);
	//printf("Temp = %s\n", temp);
	ptoken = strtok(temp, ";" );
	while( ptoken != NULL )
	{
   	     printf ("Results 2nd:%s\n", pOutData[1] );	
  	     printf ("ptoken:%s\n", ptoken );	
	     ptoken = strtok(NULL, ";" );
	}
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.