How to initialize a variable with a line from a bidimensional array in C? -


can me problem: have line i, unidimensional array p , bidimensional array(matrix) q. so, problem must initialize unidimensional array p line q without using for-loop. how can that?

    void simvardiscr(int m, int *x, double *p){//m number of elements of x , p     int i;     for(i=0;i<m;i++){         x[i]=i;         init_genrand(254);//is function mersenne-twister algorithm         p[i]=genrand_int32()%m;     } } int lantmarkov(int m,double *pi0,float **q){     int *s,k,j;double *p;     s=(int *)malloc(n*sizeof(int));     p=(double *)calloc(m,sizeof(double));     simvardiscr(m,s,pi0);     j=s[0];     for(k=0;k<n;k++){         memcpy(p, q[j], m);         simvardiscr(m,s,p);         j=s[k];     } 

the answer depends on interpretation of question: "initialize unidimensional array p line q without using for-loop" - because code doesn't initialize p line q using for loop.

  • a for loop can replaced while loop or recursion.

  • if change type of either p or q compatible (e.g. both float), can use memcpy copy q p; not sure helps because have memcpy (which has 2 bugs, doesn't work) in code.

  • you can remove memory allocation p, , have point row in q; doesn't require loop. example:

-

void simvardiscr(int m, int *x, float *p) // changed double float {     ... // no change in code }  int lantmarkov(int m,double *pi0,float **q) {     ...     for(k=0;k<n;k++){         p = q[j];         // following code changes p , j'th row of q in same manner         ...     } } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -