Search code examples
arrayscchar

How to create a 2D array of "-" in C


I want to create the following looking 2D array of "-"

enter image description here

I attempted something like this but it did not work (for 10 by 10)

char table[10][10];

for (int i = 0; i < 10; i ++){
    for (int j = 0; j < 10; j++)
    {
        strcpy(table[10][i], "-");
    }
}

Solution

  • The whole 2D array?

    If not strings, use memset(table, '-', sizeof table); to fill every byte with '-'. No for loop needed.