I have a standard variable name VarX, where X is a random number wich is in Integer Num.
How can i create a varable with the name VarNum, for example if Num = 3, VarNum would be like Var3.
How can i achieve that?
Thanks!
I have a standard variable name VarX, where X is a random number wich is in Integer Num.
How can i create a varable with the name VarNum, for example if Num = 3, VarNum would be like Var3.
How can i achieve that?
Thanks!
You can't. However there are such things as arrays.
I might be wrong.
Quoted more than 1000 times (I hope).Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
I know arrays, i was avoiding to make and array inside other array inside other array, because i already had a 2D array...
This reminded me of my first job maintaining a DOS based application. The original programmer used multiple global variables named : flag1, flag2...flag137... There were literally hundreds of them. None of his functions took parameters. All variables were GLOBAL! His function names were like random letters jumbled together. They had no relation to the function, ie. it wasn't an acronym. Amazingly the program ran and was used in a professional company that was actually fairly successful.
Ok, why is this 3 of 3 arrays wrong:
I'm doomed..Code:matrix[3][3][3]; matrix[0] = {{{{'1','2','3'},{'1','2','3'},{'1','2','3'}},{{'1','2','3'},{'1','2','3'},{'1','2','3'}},{{'1','2','3'},{'1','2','3'},{'1','2','3'}}},{{'1','2','3'},{'1','2','3'},{'1','2','3'}},{{'1','2','3'},{'1','2','3'},{'1','2','3'}},{{'1','2','3'},{'1','2','3'},{'1','2','3'}}},{{'1','2','3'},{'1','2','3'},{'1','2','3'}},{{'1','2','3'},{'1','2','3'},{'1','2','3'}},{{'1','2','3'},{'1','2','3'},{'1','2','3'}}};
An array is not a modifiable lvalue, so it cannot be assigned. It can be initialized:
Code:char matrix[3][3][3] = { {{'1','2','3'},{'1','2','3'},{'1','2','3'}}, {{'1','2','3'},{'1','2','3'},{'1','2','3'}}, {{'1','2','3'},{'1','2','3'},{'1','2','3'}}, };
7. It is easier to write an incorrect program than understand a correct one.
40. There are two ways to write error-free programs; only the third one works.*
Split the initialization across several lines. Having everything on one line is absolutely ridiculous and confusing. If I had to guess just from looking at your massive line of code, I would suspect that you are missing curly braces throughout.
Couldn't resist.
Seriously, there is a fine line between readable and spaced-out whitespace. Use whatever whitespace you think makes it easier to read. But there's no need to go too far.Code:char matrix[3][3][3] = { { { '1', '2', '3' }, { '1', '2', '3' }, { '1', '2', '3' }, }, { { '1', '2', '3' }, { '1', '2', '3' }, { '1', '2', '3' }, }, { { '1', '2', '3' }, { '1', '2', '3' }, { '1', '2', '3' }, }, };
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.
Dave wins spacing battle.
What is C++?
I thought Elysia was splitting hairs. That's why I went a step further. (Of course, that's probably how I would indent it, anyway . . . .)
That was the point.I think that is a little too far.
dwk
Seek and ye shall find. quaere et invenies.
"Simplicity does not precede complexity, but follows it." -- Alan Perlis
"Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
"The only real mistake is the one from which we learn nothing." -- John Powell
Other boards: DaniWeb, TPS
Unofficial Wiki FAQ: cpwiki.sf.net
My website: http://dwks.theprogrammingsite.com/
Projects: codeform, xuni, atlantis, nort, etc.