printf
.
Calling pushchar(p)
is equivalent to writing *p = '\0'
,
except that calling popchar()
undoes the effect of the last
pushchar
.
The stack is shallow, and the program halts with an assertion failure
if it overflows.
<header>= (U->) extern void pushchar(char *p); extern void popchar(void);
<*>= #include <assert.h> <header> static char stack[3]; static char *pstack[3]; static int next = 0; void pushchar(char *p) { assert(next < sizeof(stack)); stack[next] = *p; pstack[next++] = p; *p = 0; } void popchar(void) { char *p; assert(next > 0); p = pstack[--next]; *p = stack[next]; }
Definesnext
,popchar
,pstack
,pushchar
,stack
(links are to index).