Sunday, July 12, 2009

Error declaring variables in C?

I'm getting an error when trying to compile this line (C), my compiler doesn't seem to be recognizing the previous declaration of "nRows, nCols":





void scalarMultiply (int nRows, int nCols, int matrix[nRows][nCols], int scalar);





Is there something wrong with it?





It's from a Stephen kochan's book, so I'm guessing it's got something to do with my compiler which is MinGW Developer Studio 2.05

Error declaring variables in C?
Hi,


void scalarMultiply (int nRows, int nCols, int matrix[nRows][nCols], int scalar);








here, you can not give nRows, nCols as index to arrays.


you can give it as matrix[][] or int **matrix.


********


and anyhow giving parameter description in case of array is to make sure that they are of same type and order.
Reply:The errors given by my example line, seems to be related to the compiler not supporting "Variable Length Arrays", I haven't found a free compiler to test this yet but I'll assume that it is actually correct.





Thanks all for the feed back. Report It

Reply:hi


gosfand


you cant use your argumants in your argumants
Reply:you can not use int matrix[inRows][nCols] rather use a pointer
Reply:try another compiler like cygwin or Dev C
Reply:Just wrong code, I'm not sure but appears this author is not a C programmer.





int matrix[nRows][nCols]


replace it with int** matrix, for the declaration you wrote.
Reply:u cant define prototype like this,strictly compiler will expect only data types, but u can define variables,but cant use them..


No comments:

Post a Comment