Home > Net >  How to make an array of dictionaries in c like python?
How to make an array of dictionaries in c like python?

Time:12-06

so im trying to change my python code to c for practice and i just dont know how to make an array of dictionaries in c . here is an example of what i want to do:

from numpy import *

E = dict(ch = "", chy = "")
TabE = array([E] * 15)

so i tried to do this but i am getting an error "expected a ';'":

std::map<std::string, std::string> E = { {"ch", ""}, {"chy", ""} };
E TabE[15];

is there an alternative to that in c ?

CodePudding user response:

In the C code, E is a value, you cannot use it as a type, these are distinct things. If you wanted an array of 15 times of a single array, you can do e.g.:

std::map<std::string, std::string> E = /*...*/;
std::array<std::map<std::string, std::string>, 15> TabE;

for (size_t i = 0; i < 15;   i) {
    TabE[i] = E;
}
  • Related