puzzles/from-to/from_to.c

31 lines
462 B
C
Raw Normal View History

2024-04-02 21:01:09 +00:00
#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;
}