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

bit convertion problem

P: n/a

I have written a bitarray class which has a constructor taking bit
stream as a string parameter.but it gives me an error such that cannot
convert 'char*' to 'unsigned char*'.where I have declared bitarray as:

unsigned char *bitarray; and the constructor is:

BitArray::BitArray( const char* inputsize)
{
bitarray=new char[strlen(inputsize)+1];
strcpy(this->bitarray,inputsize);
this->length=strlen(inputsize);
return;
}

Jul 23 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
tsunami wrote:
I have written a bitarray class which has a constructor taking bit
stream as a string parameter.but it gives me an error such that cannot
convert 'char*' to 'unsigned char*'.where I have declared bitarray as:

unsigned char *bitarray; and the constructor is:

BitArray::BitArray( const char* inputsize)
{
bitarray=new char[strlen(inputsize)+1];
strcpy(this->bitarray,inputsize);
this->length=strlen(inputsize);
return;
}


'strcpy' expects a 'char*' as its first argument and you are trying to
pass a 'unsigned char*' instead. That's what's causing the error message.

It is hard to suggest a way out of this since your intent is not exactly
clear from the code provided. If you are planning to store an ASCII
representation of your "bit array" in the memory pointed by
'this->bitarray' (which is a rather strange way to implement a bit
array), why don't you just declare 'bitarray' field as a 'char*'?

--
Best regards,
Andrey Tarasevich
Jul 23 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.