How to create a string from one row of a two-dimensional character array in C

1 Answer

0 votes
#include <stdio.h>
#include <string.h>
 
#define COLS 16
 
int main() {
     
    char array2D[][COLS] = {
        "C",
        "programming",
        "language"
    };
 
    char str[COLS];
 
    strcpy(str, array2D[1]);
 
    printf("The string is: %s\n", str);
 
    return 0;
}
 
 
 
/*
run:
 
The string is: programming    
 
*/

 



answered Feb 6, 2025 by avibootz
edited Feb 7, 2025 by avibootz
...