![]() |
|
#1
|
|||
|
|||
Dynamic allocation of multi dimensional arrayHi everyone, could you tell me how to assign values to a dynamically created multi dimensional array?
I tried this code. I am getting error : Invalid direction CPP / C++ / C Code:
Anyone can help me to assign values? Last edited by admin : 22-Apr-2007 at 10:48.
Reason: Please insert your C code between [c] & [/c] tags
|
|||
|
#2
|
|||
|
|||
|
CPP / C++ / C Code:
Shouldn't that be CPP / C++ / C Code:
also... CPP / C++ / C Code:
should be CPP / C++ / C Code:
|
|
#3
|
|||
|
|||
|
I tried that also, I am getting same error at the line: scanf("%d",a[n][m][k]);
|
|
#4
|
|||
|
|||
|
Please read my previous posting more carefully. k is not l. l is not k.
|
|
#5
|
|||
|
|||
|
Quote:
Some how I got answer but some mistakes is there. I will post my code. Can you tell me what is wrong in my code?? CPP / C++ / C Code:
Last edited by admin : 22-Apr-2007 at 10:47.
Reason: Please insert your C/C++ code between [cpp] & [/cpp] tags
|
|
#6
|
|||
|
|||
|
Yes first of all sorry. My previous posting was quite wrong; I did a mistake because c++ and c got mixed up in my mind. It is true that in c you cannot refer to multidimensional array with a[n][m][l].. but in c++ you can because the compiler has more information about the dimensions of the table. .. ok .. but back to the problem.
i think you should write like: Code:
this is because l runs from 0 to (i-1), m is the 2.dimension so with every unit increase in m the pointer must jump i and finally n is for the 3.dimension..etc.. so write: CPP / C++ / C Code:
CPP / C++ / C Code:
hopefully works |
|
#7
|
|||
|
|||
|
#8
|
||||
|
||||
|
Quote:
__________________
During the election they said Obama could only be elected when pigs fly. Well, we currently have an epidemic of Swine Flu. Coincidence? |
Recent GIDBlog
Programming ebook direct download available by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Dynamic Memory Allocation - Offset Pointers | wu_weidong | C Programming Language | 6 | 24-Feb-2005 10:48 |
| template comiling problems - need expert debugger! | crq | C++ Forum | 1 | 01-Feb-2005 22:26 |
| Creating N string | gwk | C Programming Language | 3 | 21-Jul-2004 00:27 |
| 3D array dynamic memory allocation | cjwatchdog | C Programming Language | 3 | 20-Feb-2004 16:27 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The