String matrix

Asked

Viewed 7,242 times

7

How a matrix of strings?

I tried it in several ways and still did not succeed, I thought it would work but it did not work.

#include <stdio.h>
#include <stdlib.h>

int main(void){
    char matriz[2][2];
    char string1[] = "Minha string";
    matriz[0][0] = string1;
    printf("%s", matriz[0][0]);
    return 0;
}

1 answer

6


  • C and its peculiarities rs

  • The problem is with the rule of decay of the types during assignment, sometimes gets confused. In matrix[0][0] = string1;, the type of string1 is char [] and decay to char * , so you need a variable that accommodates a char pointer, even if you never explicitly declare a pointer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.