User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C section within the Software Development category of DaniWeb, a massive community of 426,446 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,211 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C advertiser: Programming Forums
Views: 3601 | Replies: 2
Reply
Join Date: Jan 2005
Posts: 9
Reputation: allomeen is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
allomeen allomeen is offline Offline
Newbie Poster

multidimensional array

  #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 >>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2004
Posts: 3,631
Reputation: Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light Dave Sinkula is a glorious beacon of light 
Rep Power: 17
Solved Threads: 142
Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: multidimensional array

  #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.
Reply With Quote  
Join Date: May 2005
Posts: 232
Reputation: Dogtree is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 2
Dogtree's Avatar
Dogtree Dogtree is offline Offline
Posting Whiz in Training

Re: multidimensional array

  #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:
void foo(int a[][10]);
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:
void foo(int **a, int m, int n);

int main()
{
  int **a = new int*[5];

  for (int i = 0; i < 5; i++)
    a[i] = new int[5];

  foo(a, 5, 5);

  for (int i = 0; i < 5; i++)
    delete [] a[i];
  delete [] a;
}
Of course, that's assuming you don't have libraries to work with. The standard vector class is well suited to this:
#include <vector>

void foo(std::vector<std::vector<int> > a);
The boost library also supports a multi_array class.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb C Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the C Forum

All times are GMT -4. The time now is 3:01 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC