Odd word problem: Difference between revisions

Simplify. Closures are not needed.
(Simplify. Closures are not needed.)
Line 294:
 
=={{header|C}}==
Using GCC nested function as closures. This can only be passed up the stack, not the other way around. It's also doable with <code>makecontext</code>, and may be possible with <code>setjmp</code>.
 
<lang c>#include <stdio.h>
#include <ctype.h>
 
static int
int do_char(int odd, void (*f)(void))
owp(int odd)
{
int ch, ret;
int c = getchar();
ch = getc(stdin);
 
void write_out if (void!odd) {
putc(ch, stdout);
putchar(c);
if (ch == EOF || ch == '.')
if (f) f();
return EOF;
}
if (ispunct(ch))
 
return 0;
if (!odd) putchar(c);
owp(odd);
 
return 0;
if (isalpha(c))
} else {
return do_char(odd, write_out);
if (ispunct(ch))
 
return ch;
if (odd) {
ret = owp(odd);
if (f) f();
putc(ch, stdout);
putchar(c);
return ret;
}
}
 
return c != '.';
}
 
int main()
main(int argc, char **argv)
{
int ich = 1;
while (do_char(ich = owp(!i, 0ch)); != EOF) {
if (ch)
 
putc(ch, stdout);
return 0;
if (ch == '.')
}</lang>
break;
}
return 0;
}
}</lang>
 
=={{header|C++}}==