![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Oct 2004
Posts: 15
Rep Power: 0
![]() |
i have the following problem:
i need to define two dimension array with unkown size,the array define after its size is computed>>>>example: #include<iostream.h> int main() { int m,n; m=8; n=9; int a[m][n]; for(int i=0;i<m;i++) { for(int j=0;j<n;n++) { a[i][j]=255; cout<<a[i][j]; } cout<<endl; } return 0; } this is not a program ,its just for explanation of my problem>>> |
|
|
|
|
|
#2 |
|
I eat cake for breakfast.
![]() ![]() ![]() ![]() Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9
![]() |
If you want to declare an array of variable length, you need to use pointers:
int m, n; m = 8; n = 9; int *a = new int [m][n]; |
|
|
|
|
|
#3 |
|
Professional Programmer
Join Date: May 2005
Location: Woo - Boot Sector!
Posts: 294
Rep Power: 4
![]() |
I read a tutorial on this ages ago, here is the sample source. sorry can't remember who wrote it (so can't legitamately attribute it to him) but it's not mine anyway...
#include <iostream.h>
#include <stdlib.h>
int main()
{
char input [100];
int i,n;
long * l;
cout << "How many numbers do you want to type in? ";
cin.getline (input,100); i=atoi (input);
l= new long[i];
if (l == NULL) exit (1);
for (n=0; n<i; n++)
{
cout << "Enter Number: ";
cin.getline (input,100); l[n]=atol (input);
}
cout << "You have entered: ";
for (n=0; n<i; n++)
cout << l[n] << ", ";
delete[] l;
system("PAUSE");
return 0;
}hope it shows you what you need to know
__________________
www.heldtogether.co.uk |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|