Skip to content

Instantly share code, notes, and snippets.

@aconbere
Created February 12, 2011 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aconbere/824180 to your computer and use it in GitHub Desktop.
Save aconbere/824180 to your computer and use it in GitHub Desktop.
int main(int argc, char *argv[]) {
int w;
int h;
int n;
int i;
int* array;
/* width and height are the first two integers on the stream */
scanf("%d", &w);
scanf("%d", &h);
printf("width: %i\n", w);
printf("height: %i\n", h);
array = malloc(w * h * sizeof(int));
read_matrix(&array, w * h);
print_matrix(&array, w, h);
}
void read_matrix(int* array, int length) {
int n;
int i;
for (i = 0; i < length; i++) {
scanf("%i", &n);
array[i] = n;
}
}
int print_matrix(int *array, int w, int h) {
int i;
printf("\n");
for (i = 0; i < w * h; i++) {
if (i && (i % w == 0)) {
printf("\n");
}
printf("%i ", array[i]);
}
printf("\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment