Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in assigning an array to the other in C

Tags:

c

pointers

Consider this code segment:

char message[255];
char newMessage[255];
int i;
for (i = 0 ; i < 255 ; i++)
     message[i] = i;
newMessage = message;

When I try to do this I get for the last line an error:

incompatible types when assigning to type ‘char[255]’ from type ‘char *

Why do I get that if the arrays has the same type? How do I fix it?

Thanks in advance

like image 299
MichBoy Avatar asked Dec 12 '22 02:12

MichBoy


1 Answers

It is not possible to assign arrays. You can use memcpy() to copy the content of one array to another.

like image 158
hmjd Avatar answered Dec 31 '22 00:12

hmjd