| | |
multidimensional array
Please support our C advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jan 2005
Posts: 9
Reputation:
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
"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
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.
C Syntax (Toggle Plain Text)
void foo(int a[][10]); void bar(int (*a)[10]);
C Syntax (Toggle Plain Text)
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; }
C Syntax (Toggle Plain Text)
#include <vector> void foo(std::vector<std::vector<int> > a);
![]() |
Similar Threads
- 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: A Virtual Piano By:-- Anurag Pareek
- Next Thread: "Talking" to Command Prompt
Views: 6733 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for C
#include .net ansi array arrays asterisks binarysearch calculate centimeter changingto char command convert copyimagefile cprogramme creafecopyofanytypeoffileinc database directory dynamic fflush file fork forloop framework functions getlasterror givemetehcodez grade graphics hacking hardware histogram homework inches include incrementoperators input iso kernel km lazy linked linkedlist linux linuxsegmentationfault list lists locate logical_drives looping loopinsideloop. lowest match matrix microsoft motherboard mysql number opendocumentformat opensource owf pattern pdf performance pointer pointers posix problem probleminc process program programming radix recursion recv research reversing scanf scripting segmentationfault sequential shape socket socketprograming spoonfeeding standard string strings structures student systemcall testing threads turboc unix user variable voidmain() wab windowsapi






