Thread: matrix

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    4

    matrix

    Hi, I have a few questions about this matrix "table"
    I can't find any wrong in it
    but errors keeps appear
    C2057 expected constant expression
    C2466 cannot allocate an array of constant size 0
    C2087: 'table' : missing subscript
    C2133: 'table' : unknown size

    here's the code
    thanks for helping

    Code:
    int lcs(string str1, string str2, string & sequence) {
        int rows=str1.length() + 1, cols=str2.length() + 1, position, seqLength;
        int table[rows][cols];
        int i, j;
        ......
    
    int main() {
    
        string inp, first, second, outp;
        int seqlen;
    
        getline(cin, inp);
        first = stripBlanks(inp);
    
        getline(cin, inp);
        second = stripBlanks(inp);
    
        seqlen = lcs(first, second, outp);
        ......

  2. #2
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Seems that rows and cols are no constants.
    Kurt

  3. #3
    ^ Read Backwards^
    Join Date
    Sep 2005
    Location
    Earth
    Posts
    282
    You can not initialize arrays (matrix is multiple arrays) with non-constant variables (that is, the program can not decide at run-time).
    However, if you want to be able for the program to decide the size of the arrays you can use pointers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C - access violation
    By uber in forum C Programming
    Replies: 2
    Last Post: 07-08-2009, 01:30 PM
  2. Matrix Help
    By HelpmeMark in forum C++ Programming
    Replies: 27
    Last Post: 03-06-2008, 05:57 PM
  3. Gauss-Jordan Matrix Inversion in C++
    By Max_Power82 in forum C++ Programming
    Replies: 3
    Last Post: 12-03-2006, 08:31 PM
  4. Matrix and vector operations on computers
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 05-11-2004, 06:36 AM