Created
March 18, 2012 15:27
-
-
Save pancurster/2075347 to your computer and use it in GitHub Desktop.
for_each in C
This file contains hidden or 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
#include <malloc.h> | |
#include <string.h> | |
#include <stdio.h> | |
#define for_each(i, list) \ | |
for(i = list; \ | |
i != NULL; \ | |
i = i->next) | |
struct lista { | |
char data; | |
struct lista* next; | |
}; | |
int main(void) | |
{ | |
struct lista l; | |
l.data = 'a'; | |
l.next = malloc(sizeof(struct lista)); | |
l.next->data = 'b'; | |
l.next->next = NULL; | |
struct lista* k; | |
for_each(k, &l) { | |
printf("%c\n", k->data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment