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!
charto0instead of a char array...{}actually is not a array initializer but a more general. it can be used to initialize primitives, structs, unions, and of course array of them.char c[].