Error C2440: Cannot convert from char * to char []
Hi,
I'm trying to split a string using strtok(), using this code snippet as a guide:
Code:
char str[] ="- This, a sample string.";
char * pch;
printf ("Splitting string \"%s\" into tokens:\n",str);
pch = strtok (str," ,.-");
while (pch != NULL)
{
printf ("%s\n",pch);
pch = strtok (NULL, " ,.-");
}
return 0;
And the code I have is:
Code:
char str[] = txt; // sample value is T,-123,-456,-789
char * pch;
pch = strtok (str,",");
while (pch != NULL)
{
sds_printf(pch);
}
return 0;
But after I compiled the code, C++ returned a C2440: "Cannot convert from char * to char []" at the char str[] = txt line. I'm having a hard time figuring it out, as I'm relatively new to C++. Can somebody tell me what I did wrong here?
Thanks in advance. :)
Re: Error C2440: Cannot convert from char * to char []
Hi DeelanMJ,
In my opinion, your code is loop not stop. Not error.
Best regards.