I am trying to understand how a Matrix works in C. I have the following code:
#include <unistd.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
int main(int argc, char* argv[]){
/* random number generator for matrix dimensions */
int xDim, yDim;
srand(time(NULL)); //init. is needed only once
xDim = (rand() % (10000+1) + 50);
yDim = (rand() % (10000+1) + 50);
/* random number generator for matrix contents */
double* myMatr;
myMatr = (double *)malloc(xDim * yDim * sizeof(double));
for(int i=0; i<xDim; i++){
for(int y=0; y<yDim; y++){
myMatr[i][y]= (double)rand()/RAND_MAX*100.0;
}
}
}
All i get is the error:
test.c:24:13: error: subscripted value is neither array nor pointer nor vector
myMatr[i][y]= (double)rand()/RAND_MAX*100.0;
Thanks for any help!
Aucun commentaire:
Enregistrer un commentaire