Walid-Shouman
11/27/2016 - 4:44 PM

C tips and tricks: transfering data from pointer to array

C tips and tricks: transfering data from pointer to array

Caution

This Gist is a WIP

Copy pointer to array

Unfortunately we can't assign an allocated space from a pointer to an array directly
That actually gives the following output error: incompatible types when assigning to type ...

Either use string.h's memcpy or do a manual loop.

Memcpy way

memcpy()

Manual way

for(long i = sizeof(tmp)/sizeof(tmp[0]); i--; ) tmp[i] = text[i];

Reference: incompatible types when assigning to type 'array[256]' from type 'array *'