Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/rajasharan/foreach

foreach utility function for C language
https://github.com/rajasharan/foreach

Last synced: 3 days ago
JSON representation

foreach utility function for C language

Awesome Lists containing this project

README

        

USAGE

#include "foreach.h"

typedef Struct Element {
int key;
double value;
} Element;

int main()
{
Element elems[5];
/* initialize elems */
int i;
for (i=0; i<5; i++)
elems[i].key = i;

Array *arr = create_array(elems, 5, sizeof(Element));
arr->foreach(arr, my_print);
return 0;
}

int my_print(void *elem)
{
Element e = (Elemenet *) elem;

/* do stuff with e */
printf("%d\n", e->key);

return 0; /* SUCCESS */
}

COMPILING

% gcc foreach.c test_foreach.c
% ./a.out
0
1
2
3
4