Skip to content

Instantly share code, notes, and snippets.

@Mon-Ouie
Created July 18, 2010 10:23
Show Gist options
  • Select an option

  • Save Mon-Ouie/480294 to your computer and use it in GitHub Desktop.

Select an option

Save Mon-Ouie/480294 to your computer and use it in GitHub Desktop.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void map_array(int *array, int size, int (^block)(int value)) {
for (int i = 0; i < size; i++)
array[i] = block(array[i]);
}
int main(int argc, char **argv) {
int array[] = {
30, 60, 17, 120, 42, 25, 32, 47,
93, 75, 88, 230, 1270, 300, 400,
224, 440, 89, 330, 1, -100, 5052
};
int tab_size = sizeof(array) / sizeof(int);
map_array(array, tab_size, ^(int val) {
return val * 2;
});
for (int i = 0; i < tab_size; i++)
printf("%d ", array[i]);
printf("\n");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment