Click to See Complete Forum and Search --> : newb question about c strings


Jumux
04-17-2003, 12:29 AM
specifically, whats the best way to clear a string say char string[100], after its used

EscapeCharacter
04-17-2003, 12:38 AM
you could set string[0] to '\0'

gfreehed
04-18-2003, 03:57 PM
You could also use bzero(string, 100) or memset(string, 0, 100).

Modorf
04-18-2003, 04:33 PM
depending on if you want to still use the string later or just destroy it and reclaim the memory.

you will want to do either

char *pointer = malloc(100*sizeof(char));
pointer[0] = \0; // will assign the string to null.
free(pointer); // deallocates the memory

nathan.

binaryDigit
04-19-2003, 11:17 AM
Originally posted by Modorf
depending on if you want to still use the string later or just destroy it and reclaim the memory.

you will want to do either

char *pointer = malloc(100*sizeof(char));
pointer[0] = \0; // will assign the string to null.
free(pointer); // deallocates the memory

nathan.
you should pay more attention.
he said char string[100]
he didn't say anything about dynamic memory allocation.