From: toudi Newsgroups: comp.os.msdos.djgpp Subject: Re: Flipping an image Date: Wed, 14 Jul 1999 00:57:29 +0200 Organization: beautiful piramids Lines: 53 Sender: pienkny AT pa52 DOT warszawa DOT ppp DOT tpnet DOT pl Message-ID: <378BC459.7CBCDC2F@friko6.onet.pl> References: <7mf2qk$nlg$1 AT rockall DOT cc DOT strath DOT ac DOT uk> <7mfdr3$m9r$1 AT taliesin DOT netcom DOT net DOT uk> NNTP-Posting-Host: pa52.warszawa.ppp.tpnet.pl Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-2 Content-Transfer-Encoding: 7bit X-Trace: news.onet.pl 931907447 15187 212.160.52.52 (13 Jul 1999 23:10:47 GMT) X-Complaints-To: abuse AT onet DOT pl NNTP-Posting-Date: 13 Jul 1999 23:10:47 GMT X-Mailer: Mozilla 4.5 [pl] (Win95; I) X-Accept-Language: pl To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com > Alan Wills wrote in message <7mf2qk$nlg$1 AT rockall DOT cc DOT strath DOT ac DOT uk>... > >void flip_image(int array[], int rows, int cols) > >{ > >int row_count, col_count, total_pixelsp; > > > > for(row_count = 0; row_count < rows; row_count++) > > { > > for(col_count = 0; col_count < cols; col_count++) > > { > > // Something like this ? (note: this is untested) > tmp = array[row_count * cols + col_count]; > array[row_count * cols + col_count] = array[(row_count + 1) * cols - 1 - > col_count]; > array[(row_count + 1) * cols - 1 - col_count] = tmp; > > > } > > } > >} I think you should use second array. Your code should look like this (this is untested too): void flip_image(int array[], int rows, int cols) { int row_count, col_count, total_pixelsp; int *atmp; // to dynamically allocate memory atmp = (int*)malloc(sizeof(int) * rows * cols); for(row_count = 0; row_count < rows; row_count++) for(col_count = 0; col_count < cols; col_count++) atmp[row_count * cols + cols - col_count] = array[row_count * cols + col_count]; // second array is flipped in this moment for(row_count = 0; row_count < rows; row_count++) memcpy(&array[row_count * cols], atmp[row_count * cols], sizeof(int) * cols]); // copy second array to first array free(atmp); } Maybe there is small mistake but the idea is right. -- mailto:pienkny AT friko6 DOT onet DOT pl +4822368951