matrix

This is a discussion on matrix within the C++ Programming forums, part of the General Programming Boards category; Hi, I have a few questions about this matrix "table" I can't find any wrong in it but errors keeps ...

  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
    ZuK
    ZuK is offline
    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, 04:57 PM
  3. Gauss-Jordan Matrix Inversion in C++
    By Max_Power82 in forum C++ Programming
    Replies: 3
    Last Post: 12-03-2006, 07: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21