Pinball
10-25-2001, 05:18 PM
This may be really silly, but I don't seem to make any progress towards the answer. This is the thing:
let's say I want to allocate a char array: (array[] = "Hellow"), by calling calloc. Now do I need to ask calloc for 6 o 7 objects of size char?
I do want to have space for the null terminator '\0':
for example:
char array[] = "hellow";
char *str;
str = calloc(strlen(array)+1, sizeof(char));
/* is the strlen(array)+1 ok? */
/* or should it be just (strlen(array) */
Thanks, for any directions here...
let's say I want to allocate a char array: (array[] = "Hellow"), by calling calloc. Now do I need to ask calloc for 6 o 7 objects of size char?
I do want to have space for the null terminator '\0':
for example:
char array[] = "hellow";
char *str;
str = calloc(strlen(array)+1, sizeof(char));
/* is the strlen(array)+1 ok? */
/* or should it be just (strlen(array) */
Thanks, for any directions here...