Different types of data in a C array


I am currently doing an array in the following way:

char count[3][1] = {
    ["test"] = {0},
    ["prueba"] = {1},
    ["stack"] = {2}

The problem is that when compiling it does not recognize me well, because there are different types of data.

Any ideas to solve it, is the first time I work with arrays of this type.

Salutations and thanks.

asked by akroma 13.05.2017 в 22:35

1 answer


You can not mix different types in an array in C. Also, this is not the correct syntax. What I suggest, is to define a structure with two fields and then a array of structures as I show below:

struct asociacion {
   char nombre [10];
   int valor;

struct asociacion count [3] = {
    {"test", 0},
    {"prueba", 1},
    {"stack", 2}



count [2] .name would give "stack"
  count [1] .value would give 1

I could respond better if I knew the purpose of the array

answered by 19.05.2017 в 17:20