Connecting Tech Pros Worldwide Forums | Help | Site Map

error C2440: '=' : cannot convert from 'char *' to 'char'

Member
 
Join Date: Jul 2008
Posts: 34
#1: Sep 5 '08
error is as stated in the topic above:
error C2440: '=' : cannot convert from 'char *' to 'char'

code is below
Expand|Select|Wrap|Line Numbers
  1. void handleOneLine(string string1)
  2. {
  3.     char * cstr, *p;
  4.     int counter;
  5.     string str (string1);
  6.     char data1, data2, data3;
  7.  
  8.     cstr = new char [str.size()+1];
  9.     strcpy (cstr, str.c_str());
  10.  
  11.     // cstr now contains a c-string copy of str
  12.  
  13.     int count = 0;
  14.     p=strtok (cstr,",");
  15.     count++;
  16.     while (p!=NULL)
  17.     {
  18.         p=strtok(NULL,",");
  19.         if( count == 1 )
  20.         {            
  21.             data1 = p;
  22.             searchTree(treeObj->root ,data1);
  23.         }
  24.         else if( count == 2 )
  25.         {
  26.             data2 = p;
  27. //            treeNodeObj->setLeft(data2);
  28.         }
  29.         else if( count == 3 )
  30.         {
  31.             data3 = p;
  32. //            treeNodeObj->setRight(data3);
  33.         }
  34.         count++;
  35.         if( count == 3 )
  36.             break;
  37.     }
  38.  
  39.     delete[] cstr; 
  40. }
  41.  
the error is below:
Expand|Select|Wrap|Line Numbers
  1. error C2440: '=' : cannot convert from 'char *' to 'char'
  2. 1>        There is no context in which this conversion is possible
  3.  
and the lines from which the errors are caused are:
Expand|Select|Wrap|Line Numbers
  1. data1 = p;
  2. data2 = p;
  3. data3 = p;
  4.  

how can i solve this problem?
i will check the forum every 5 mins so plz do check back if u have posted a qn for me..
thanks in advance :)

JosAH's Avatar
Expert
 
Join Date: Mar 2007
Posts: 10,611
#2: Sep 5 '08

re: error C2440: '=' : cannot convert from 'char *' to 'char'


Well, data1, data2 and data3 are just chars and p is a pointer to a char. You
cannot implicitly convert one to the other (as your error diagnostic message showed).
Probably you mean "data1= *p" etc.

kind regards,

Jos
Member
 
Join Date: Jul 2008
Posts: 34
#3: Sep 5 '08

re: error C2440: '=' : cannot convert from 'char *' to 'char'


Quote:

Originally Posted by JosAH

Well, data1, data2 and data3 are just chars and p is a pointer to a char. You
cannot implicitly convert one to the other (as your error diagnostic message showed).
Probably you mean "data1= *p" etc.

kind regards,

Jos

yup u r right :D
thanks ever so much :)
Reply