Writing to char [][]

Hi, I have a new frustration on my hands. I'm trying to have a 2D array for i.e.
char cBuf[1000][50] = {0};,
now I assume, that I have a block of 1000 cBufs, and each of them has a place for aditional 50 chars, so I basically have a cBuf that goes from cBufs[0 - (1000*50-1)]. Now I'm simply trying to write some text on each "line" in cBufs 2D array, give you an example:

1
2
3
cBuf[0] = "Wooooork!!";
cBuf[1] = "still not?";
cBuf[2] = "ok, i give up";


so now in my head this would look like this:

cBuf's memory:
"Wooooork!!\0__________________________________________________" <- cBuf[0]
"still not?\0__________________________________________________" <- cBuf[1]
"ok, i give up\0_______________________________________________" <- cBuf[2]
...
.
.

ok all good and well, comes compile time, I get an error: "Expression must be a modifiable lvalue error". Where is my logic faulty?? What am I missing?

Thanks for any help.
Oo, and one more thing, if anybody happens to know, what this is, it's in C#, and how could this be implemented in c++:

1
2
3
4
5
6
7
8
9
10
11
12
 private static Dictionary<long, string> CreateWordDictionary()
 {
     return new Dictionary<long, string>
                {
                    {0, "zero"},
                    {1, "one"},
                    {2, "two"},
                    {3, "three"},
                    {4, "four"},
                    {5, "five"}
};
}


You have to use strcpy:
strcpy(cBuf[0],"text"); // copy "text" to cBuf[0]

or use C++ strings:
1
2
string cBuf[1000]; 
cBuf[0]="fghfghfgh";


----

I think you want to create a map:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
map<long,string> Dictionary;

int main()
{

Dictionary[0]="zero";
Dictionary[1]="one";
Dictionary[2]="two";
Dictionary[3]="three";
// ...
cout <<Dictionary[3]; 


}



http://www.cplusplus.com/reference/stl/map/
Last edited on
Topic archived. No new replies allowed.