-
malloc of char arrays
A friend tells me that in C when u malloc a char array u have to allocate length of the string + 2 (1 for the '\0' and 1 cause C needs it for some reason, i forget why tho). Just windering if this is right? and if i just statically allocate the array in the variables declaration that i only need to allocate for the size of the string.
Thanx for any help you can give.
-
For chars, you're simply specifying the number of bytes/chars to be allocated. That means the number of characters, plus one for the null character.
-
> Just windering if this is right?
Nope, it's just strlen(string) + 1 if you want to allocate memory for string
-