-
-
Save shyiko/1da758cb2b866ccd541539398e8571cf to your computer and use it in GitHub Desktop.
for_each in C
This file contains 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