By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,052 Members | 1,231 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,052 IT Pros & Developers. It's quick & easy.

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

P: 34
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 :)
Sep 5 '08 #1
Share this Question
Share on Google+
2 Replies


Expert 10K+
P: 11,448
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
Sep 5 '08 #2

P: 34
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 :)
Sep 5 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.