Pxem, 11 + 52 = 63 bytes
.c.w.n\0.a.s
Filename
\1.rL.w.i.c0.x.t.e.c.-.m.oXX\1.a.c!.x.s\1.+XX\1.a\1.+.a.e
Try it online!
What I have golfed
- EOF case out of the loop
- How subroutine works
Pxem, 13 + 58 = 71 bytes
.s.c.w.n\0.a.s
Filename
\1.rL.w.i.c\1.+\1.y.e.d.a.c0.x.e.o.s\1.rXX1.a.c1.z.s\1.+XX0.a.a
Try it online!
How I golfed
- Push zero by
\1.r
instead of aa.%
.
- Put number of zeros at bottom then digit or EOF above.
Pxem, 16 + 61 = 77 bytes
.c.w.naa.%.a.s.s
Filename
aa.%.t.w.i.c\1.y.m.e.d.a.c0.x.m.e.m.-.t.oXX1.a1.z\1.m.+.tXX.a.a
Try it online!
Explained
Filename.
aa.%.t Store 0 to register because it is initialized with null.
.w Loop
.i Push getchar
.c\1.y If EOF
.m.e.d Push register, call subroutine, exit
.a
.c0.x If top is greater than 48
.m.e Push register, call subroutine
.m.-.t Reset register to 0
.o putchar pop
XX1.a Push 49
1.z If pop is NOT 49
\1.m.+.t Increment register
XX.a
.a End loop
Content as subroutine. Different space with filename, when return stack is concatenated to caller's stack.
.c.w If top is not zero
.n print popped value as numeric integer
aa.%.a
.s.s Clean up
0
s replaced with?11
? \$\endgroup\$10
as no modifications to the output were also needed, as most answers suggest \$\endgroup\$