unsigned char[10]
this is a C issue, but i didn't find a C forum so i m posting this here.
I have an unsigned char lala[10];
and want to use strcpy(lala, "xaxa");
the problem is that strcpy ' 1st argument is char* and won't compile. any ideas? i wouldn't like to change the variable definition.
thx for your time
[345 byte] By [
pink floyd] at [2007-11-18 19:28:10]

# 1 Re: unsigned char[10]
can u typecast the int array?
nark at 2007-11-9 0:32:32 >

# 2 Re: unsigned char[10]
Hi,
don't change ur variable defination. the problem is defination of strcpy(), the 1st parameter is char * and not unsigned char.
U can typecast the first parameter to char *, and ur problem will be solved.
Ashish
# 3 Re: unsigned char[10]
Originally posted by bashish
Hi,
don't change ur variable defination. the problem is defination of strcpy(), the 1st parameter is char * and not unsigned char.
U can typecast the first parameter to char *, and ur problem will be solved.
Ashish
yeah, why cant u do that?
nark at 2007-11-9 0:35:36 >

# 4 Re: unsigned char[10]
You could also try memcpy but you'd have to supply the size of the string being copied.
cup at 2007-11-9 0:36:44 >

# 5 Re: unsigned char[10]
Originally posted by pink floyd
I have an unsigned char lala[10];
and want to use strcpy(lala, "xaxa");
the problem is that strcpy ' 1st argument is char* and won't compile. any ideas? i wouldn't like to change the variable definition.
thx for your time
What compiler do u use? because in Visual Studio it works pretty fine:
unsigned char a[10];
strcpy(a,"aaa");
# 6 Re: unsigned char[10]
I've just seen it works in Solaris 5.7. So, are you sure u don't do sth wrong?
# 7 Re: unsigned char[10]
using VC++ 6
I get:
error C2664: 'strcpy' : cannot convert parameter 1 from 'unsigned char [10]' to 'char *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
Guysl at 2007-11-9 0:39:39 >

# 8 Re: unsigned char[10]
As pointed out a number of times, strcpy wants a "char *" not and "unsigned char *".
You either need to:
1) do a type cast
2) ceate a polymophic set of string routines that work with unsigned char
# 9 Re: unsigned char[10]
Guysl, does your file have a .c or a .cpp extension? I don't know why, but if it has a .c extension not even a warning is shown and it works fine. Doesn't work with a .cpp extension though...
Anyway, it works under gcc of Solaris (which I suppose is the most "standard" compiler). Also, if you do typecasting:
strcpy((char*)a,"aaa")
it works fine even under VC++ and with .cpp file.
Regards,
Theodore
# 10 Re: unsigned char[10]
yiannakop,
I've used cpp extension, it would have been weird
if you'd succeded to compile it with cpp too ;)
Guysl at 2007-11-9 0:42:50 >

# 11 Re: unsigned char[10]
Originally posted by Guysl
yiannakop,
I've used cpp extension, it would have been weird
if you'd succeded to compile it with cpp too ;)
Why?
# 12 Re: unsigned char[10]
...because if we both use the same compiler with the same
code and same extention , and one is compiled the second not -
I consider it weird (though there must be a reasonable explanation for that behaviour).
Guysl at 2007-11-9 0:44:48 >

# 13 Re: unsigned char[10]
just wondering, would it be that difficult to write ur own strcpy?
nark at 2007-11-9 0:45:46 >
