Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old May 8th, 2005, 8:40 AM   #1
amin1982
Newbie
 
Join Date: Oct 2004
Posts: 15
Rep Power: 0 amin1982 is on a distinguished road
Post question(ARRAy)

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>>>
amin1982 is offline   Reply With Quote
Old May 8th, 2005, 8:59 AM   #2
Ooble
I eat cake for breakfast.
 
Ooble's Avatar
 
Join Date: Jul 2004
Location: In my box.
Posts: 4,434
Rep Power: 9 Ooble is on a distinguished road
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];
I hope that's right...
__________________
Me :: You :: Them
Ooble is offline   Reply With Quote
Old May 8th, 2005, 10:54 AM   #3
LOI Kratong
Professional Programmer
 
Join Date: May 2005
Location: Woo - Boot Sector!
Posts: 294
Rep Power: 4 LOI Kratong is on a distinguished road
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
LOI Kratong is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:56 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC