Skip to content

Instantly share code, notes, and snippets.

@Siapran
Last active August 29, 2015 14:17
Show Gist options
  • Save Siapran/de7b68766cc5dd0f7826 to your computer and use it in GitHub Desktop.
Save Siapran/de7b68766cc5dd0f7826 to your computer and use it in GitHub Desktop.
GCL usage
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
typedef const char* str;
#define TYPE str
#include "vector.h"
#include "vector.def"
#undef TYPE
#define KEY_TYPE str
#define VALUE_TYPE int
#include "map.h"
#include "map.def"
#undef KEY_TYPE
#undef VALUE_TYPE
int main()
{
size_t i;
vector_t(str) my_vector;
map_t(str, int) my_map;
const char sentence[] = "It is often said that before you die your life passes before your eyes. It is in fact true. It's called living.\0";
const char delimiter[] = " \0";
char *token;
token = strtok(sentence, delimiter);
vector_init(str)(&my_vector, 0);
map_init(str, int)(&my_map, strcmp);
while (token != NULL) {
vector_push_back(str)(&my_vector, token);
token = strtok(NULL, delimiter);
}
for (i = 0; i < my_vector.size; ++i) {
++map_at(str, int)(&my_map,
my_vector.data[i]);
printf("%s\t: %d\n",
my_vector.data[i],
map_at(str, int)(&my_map,
my_vector.data[i]));
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment