Skip to content

Instantly share code, notes, and snippets.

@andresv
Created March 30, 2012 15:47
Show Gist options
  • Save andresv/2252378 to your computer and use it in GitHub Desktop.
Save andresv/2252378 to your computer and use it in GitHub Desktop.
Matrix memmove
#include <stdio.h>
#include <string.h>
#include <stdint.h> //uint8_t and friends
#define ROWS 3
#define COLS 4
int main(void){
uint8_t m[ROWS][COLS] = {{1,2,3,4}, {5,6,7,8}, {9,10,11,12}};
uint8_t i,j;
uint8_t rows = ROWS;
uint8_t cols = COLS;
for (i=0; i<rows; i++) {
for (j=0; j<cols; j++) {
printf("m[%d][%d] = %d\n", i, j, m[i][j]);
}
}
printf("\n\n");
// viska minema teine rida
// nagu n2ha liigutatakse rida indexiga 2 sinna kust algab rida indexiga 1
memmove(&(m[1][0]), &(m[2][0]), COLS);
rows = 2; // sest nyyd on ridu v2hem
for (i=0; i<rows; i++) {
for (j=0; j<cols; j++) {
printf("m[%d][%d] = %d\n", i, j, m[i][j]);
}
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment