Char matrix in C++? -
i have been trying hard c++ exercise no avail.. how create char matrix holding 4 words, each letter of word on char space? attempt.
want use null know string ends. , due instructions of excercise have use char matrix. can see tried different aproaches vector[0] , rest. neither of them works.
int largo = 3; char ** vector = new char* [largo+1]; (int = 0; < largo; i++){ vector[i] = new char[10]; } vector[0] = "f","u","t","b","o","l"; vector[1] = "automata"; vector[2] = "fut"; vector[3] = "auto"; vector[largo+1] = null;
i have been trying hard c++ exercise no avail.. how create char matrix holding 4 words, each letter of word on char space?
no problem. can use std::vector
, std::string
task. in fact std::string
can c-string (null terminated since them) data()
.
std::vector<std::string> vector { "futbol", "automata", "fut", "auto" };
if want use c "features" on other hand:
const int largo = 3; char** vector = new char* [largo+1]; (int = 0; < largo + 1; ++i) vector[i] = new char[10]; strcpy(vector[0], "futbol"); strcpy(vector[0], "automata"); strcpy(vector[0], "fut"); strcpy(vector[0], "auto");
Comments
Post a Comment