Copy part of an Char Array

I have to cut the day month and year out of a date string (mm/dd/yy). I can get the piece of the array out and print it using "printf ("%s\n",pch);" but how would I assign it to a variable instead of print it out.

counter =0;
char str[8];
strcpy(str, birthDate);
char* pch;

pch = strtok (str,"/");
while (pch != NULL)
{
counter = 0;
printf ("%s\n",pch);// this line works and prints out the correct data

pch = strtok (NULL, "/");
if (counter = 0)
strcpy(day, pch);//here i need to assign the first piece to day
else if (counter = 1)
strcpy(month, pch);//here i need to assign the second piece
else if (counter = 2)
strcpy(year, pch);//here i need to assign the third piece
counter++;
}

Can anyont point me in the right direction to copy the tokenized array?

thanks
Use the Boost String Algorithms library. boost::split() will split the string and store the components in a vector using 3 lines of code.

And please always post code inside of [code] tags.
or use std:string and its functions :P... no additional boost required...
Topic archived. No new replies allowed.