Created
February 12, 2011 22:05
-
-
Save aconbere/824180 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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