Malloc + 2d arrays + C

Ioannis Sidiropoulos sidiropoylosi at yahoo.gr
Tue Mar 19 13:05:01 EET 2002


Xairetw!

Prospa8w na grapsw ena (to prwto mou) programma pou exei na kanei me

images. Exw loipon mia synarthsh pou pairnei enan pointer se 2d

array (to image) kai to epeksergazetai. Mesa s'ayth thn synarthsh kanw

malloc gia enan temp 2d array wste na ginei olh h epksergasia s'ayton kai

prin epistrepsw ap'thn synarthsh na ton kanw copy sto actual image (ksexasa

na pw oti einai char arrays):

void process(int size, char **image) {

  int arraySize = 2*size+1; //arraySize = to mhkos ths pleyras toy#

                            // TETRAGWNOU array

  char **tmp = malloc(arraySize*sizeof(char *));

  for (l;l<arraySize;l++) {

    tmp[i] = malloc(arraySize*sizeof(char))

  }

  // edw ginetai to processing ston tmp

  // kai twra 8a ton kanw copy ston image

  // kai 8a eley8erwsw th mnhmh

memmove (image, tmp, arraySize);

free(tmp);

}

Parolo pou kanei compile to programma me petaei Segm. Fault

otan to trexw, ti exw kanei la8os???

TIA

Giannhs



---------------------------------
Do You Yahoo!?
Αποκτήστε την δωρεάν σας@yahoo.gr διεύθυνση  στο Yahoo! Mail.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.hellug.gr/pipermail/linux-greek-users/attachments/20020319/3ce8a06d/attachment.htm>


More information about the Linux-greek-users mailing list