You do not need to clear them if you use strings with a null character in C style. You only need to set the element after the final character in the string to NUL ('\ 0').
For instance,
char buffer [30] = {'H', 'i', '', 'T', 'h', 'e', ββ'r', 'e', ββ0};
// or, similarly:
// char buffer [30] = "Hi There"; // either example will work here.
printf ("% s", buffer);
buffer [2] = '\ 0';
printf ("% s", buffer)
displays
Hi there
Hi
although it is true that buffer[3] == 'T' .
source share