•
•
•
•
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
![]() |
•
•
Join Date: Jan 2005
Posts: 9
Reputation:
Rep Power: 0
Solved Threads: 0
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 :
<< moderator edit: added [code][/code] tags >>
"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';
}
}
} I find the diagnostic message quite self-explanitory. You can't do [][]. You can do [][5], for example.
•
•
•
•
declaration of `c' as multidimensional array must have bounds for all dimensions except the first
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:
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:
Of course, that's assuming you don't have libraries to work with. The standard vector class is well suited to this:
The boost library also supports a multi_array class.
void foo(int a[][10]); void bar(int (*a)[10]);
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;
}#include <vector> void foo(std::vector<std::vector<int> > a);
![]() |
•
•
•
•
•
•
•
•
DaniWeb C Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Multidimensional array sort problem (C++)
- Question regarding multidimensional array for navigation bar (Graphics and Multimedia)
- Synchronized Multidimensional Array (Java)
- Sort multidimensional array on more than one column? (ASP)
- multidimensional array merge using PHP (PHP)
- How to Sort a MultiDimensional Array (C)
- Java Multidimensional Arrays (Java)
Other Threads in the C Forum
- Previous Thread: Context Senstitive Help for a program ?
- Next Thread: "Talking" to Command Prompt



Linear Mode