I have:
char message1[100];
char message2[100];
When I try to do message1 = message2
, I get error:
incompatible types when assigning to type
‘char[100]’
from type‘char *’
I have functions like
if(send(clntSocket, echoBuffer, recvMsgSize, 0) != recvMsgSize){
DieWithError("send() failed")
}
inbetween. Could these mess things up somehow? :(
I have a feeling maybe you can't do =
on char arrays or something, but I looked around and couldn't find anything.
You can't assign anything to an array variable in C. It's not a 'modifiable lvalue'. From the spec, §6.3.2.1 Lvalues, arrays, and function designators:
The error message you're getting is a bit confusing because the array on the right hand side of the expression decays into a pointer before the assignment. What you have is semantically equivalent to:
Which gives the right side type
char *
, but since you still can't assign anything tomessage1
(it's an array, typechar[100]
), you're getting the compiler error that you see. You can solve your problem by usingmemcpy(3)
:If you really have your heart set on using
=
for some reason, you could use use arrays inside structures... that's not really a recommended way to go, though.Your suspicions are correct. C (I'm assuming this is C) treats an array variable as a pointer.
You need to read the C FAQ about arrays and pointers: http://c-faq.com/aryptr/index.html