How to replace the first line of a 2D array of characters with spaces in C

1 Answer

0 votes
#include <stdio.h>

#define ROWS 5
#define COLS 8
 
int main(void) {
    char array[ROWS][COLS] = {
        {'a','a','a','a','a','a','a','\0'},
        {'b','b','b','b','b','b','b','\0'},
        {'c','c','c','c','c','c','c','\0'},
        {'d','d','d','d','d','d','d','\0'},
        {'e','e','e','e','e','e','e','\0'},
    };

    for (int j = 0; j < COLS - 1; j++) {
        array[0][j] = ' ';
    }
    
    for (int i = 0; i < ROWS; i++) {
        printf("%s\n", array[i]);
    }
}
 
 
 
 
/*
run:

bbbbbbb
ccccccc
ddddddd
eeeeeee
 
*/

 



answered Jun 22, 2024 by avibootz
edited Jun 24, 2024 by avibootz

Related questions

2 answers 134 views
1 answer 204 views
1 answer 236 views
1 answer 169 views
1 answer 101 views
...