Like @OliCharlesworth , the best way is to use memset
:
char bla[20]; memset(bla, ' ', sizeof bla - 1); bla[sizeof bla - 1] = '\0';
Note that in GNU C, you can also use the following extension (range-designated initializers):
char bla[20] = {[0 ... 18] = ' ', [19] = '\0'};
source share