Results 1 to 2 of 2

Thread: Error C2440: Cannot convert from char * to char []

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2009
    Posts
    9

    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.

  2. #2
    Lively Member
    Join Date
    Mar 2010
    Posts
    124

    Re: Error C2440: Cannot convert from char * to char []

    Hi DeelanMJ,
    In my opinion, your code is loop not stop. Not error.

    Best regards.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width