I want to initialize all members of an array of char
arrays with one default string "default"
.
What I have so far is either:
char a[10][8];
for(int i = 0; i < 10; i++)
{
strcpy(&a[i][0],"default");
}
or alternatively:
char a[10][8] = {
{"default"}, {"default"}, {"default"}, {"default"}, {"default"},
{"default"}, {"default"}, {"default"}, {"default"}, {"default"}
};
Is there a way in the C syntax to abbreviate this in a simpler way?
I know that there is the similar question How to initialize all members of an array to the same value? but the answers there focus on how to initialize an one-dimensional int
array with int
values, not a two-dimensional char
array with strings.