Reputation: 785
How do I achieve the dynamic equivalent of this static array initialization in C?
char c[] = {}; // Sets all members to '\0';
In other words, create a dynamic array with all values initialised to the termination character. Is the below method correct? Is there any better method?
str = (char*)malloc(length*sizeof(char));
memset(str, 0, length);
Thanks!
Upvotes: 1
Views: 199