Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/rajasharan/foreach
- Owner: rajasharan
- Created: 2012-03-05T02:51:38.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2012-03-05T02:52:57.000Z (over 12 years ago)
- Last Synced: 2023-03-12T06:04:02.793Z (over 1 year ago)
- Language: C
- Homepage:
- Size: 85.9 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: readme
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