Created
September 5, 2022 17:43
-
-
Save zoeisnowooze/c418fa9d9d129ba8d0599c5d64bfe81f to your computer and use it in GitHub Desktop.
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 <stdbool.h> | |
#include <stdio.h> | |
typedef bool (*gen_f)(size_t *i); | |
gen_f from_to(size_t from, size_t to) { | |
size_t i = from; | |
bool g(size_t * j) { | |
if (i <= to) { | |
*j = i++; | |
return true; | |
} else { | |
return false; | |
} | |
} | |
return g; | |
} | |
int main(int argc, char **argv) { | |
gen_f gen = from_to(5, 7); | |
size_t i; | |
while (gen(&i)) { | |
printf("%ld\n", i); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment