Different types of data in a C array

1

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
source

1 answer

2

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}
};
  

Then,

     

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