Alex Rivera | Logout

What's the best way to reset a char[] in C?

Asked 2009-11-14T23:04:24.187
9

I use a string:

char    word[100];

I add some chars to each position starting at 0. But then I need be able to clear all those positions so that I can start add new characters starting at 0.

If I don't do that then if the second string is shorten then the first one I end up having extra characters from the first string when adding the second one since I don't overwrite them.

Edit
Report

1 Answer

1

You could assign a null terminator to the first position of the char array.

*word = '\0';
answered 2009-11-14T23:06:34.007

Your Answer