multidimensional array

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jan 2005
Posts: 9
Reputation: allomeen is an unknown quantity at this point 
Solved Threads: 0
allomeen allomeen is offline Offline
Newbie Poster

multidimensional array

 
0
  #1
May 24th, 2005
Hi, I having this error and i don't know how to fix it, can anybody help please:
"declaration of `c' as multidimensional array must have bounds for all dimensions except the first", i'm getting this error because of :

void lcs::LCS_Length(int X[], int Y[], int c[][], char b[][],  int m, int n)
{
	for( int i = 1; i < m; i++)
		c[i][0] = 0;
	for( int j = 1; j < n; j++)
		c[0][j] = 0;
	for( int i = 1; i < m; i++)
		for( int j = 1; j < n; j++)
		{
			if( X[i] == Y[j])
			{
				c[i][j] = c[i - 1][j - 1] + 1;
				b[i][j] = 'D';
			}

			else if(c[i - 1][j] >= c[i][j - 1])
			{
				c[i][j] = c[i - 1][j];
				b[i][j] = 'U';
			}
			else
			{
				c[i][j] = c[i][j - 1];
				b[i][j] = 'L';
			}
		}
}
<< moderator edit: added [code][/code] tags >>
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,461
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 255
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: multidimensional array

 
0
  #2
May 24th, 2005
I find the diagnostic message quite self-explanitory.
declaration of `c' as multidimensional array must have bounds for all dimensions except the first
You can't do [][]. You can do [][5], for example.
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 232
Reputation: Dogtree is an unknown quantity at this point 
Solved Threads: 3
Dogtree's Avatar
Dogtree Dogtree is offline Offline
Posting Whiz in Training

Re: multidimensional array

 
0
  #3
May 24th, 2005
You can omit the array size for the first dimension because array names are almost always converted to a pointer to the first element, so any size information is lost. That feature only applies to the first dimension, so you have to provide size information for the second dimension because the conversion to a pointer makes it a pointer to an array of N. These two function declarations are equivalent:
  1. void foo(int a[][10]);
  2. void bar(int (*a)[10]);
To avoid those errors, you can always provide sizes for all dimensions until you're comfortable with the rules. However, for arbitrary sizes in all dimensions, you have no choice but to use a dynamic array:
  1. void foo(int **a, int m, int n);
  2.  
  3. int main()
  4. {
  5. int **a = new int*[5];
  6.  
  7. for (int i = 0; i < 5; i++)
  8. a[i] = new int[5];
  9.  
  10. foo(a, 5, 5);
  11.  
  12. for (int i = 0; i < 5; i++)
  13. delete [] a[i];
  14. delete [] a;
  15. }
Of course, that's assuming you don't have libraries to work with. The standard vector class is well suited to this:
  1. #include <vector>
  2.  
  3. void foo(std::vector<std::vector<int> > a);
The boost library also supports a multi_array class.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 6733 | Replies: 2
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC