Anonymous user
Odd word problem: Difference between revisions
m
→{{header|REXX}}: split compound statements, used a template for the output section, simplified the code.
m (→{{header|Lua}}: minor restructure to eliminate EOF test (in case that could be considered "cheating", since period is guaranteed terminator)) |
m (→{{header|REXX}}: split compound statements, used a template for the output section, simplified the code.) |
||
Line 2,266:
The REXX program writes some header information to aid in visual fidelity when displaying the output to the
<br>screen (also a blank line is written to make the screen display righteous; it's assumed that writing titles and
<br>blank lines doesn't break the spirit of the restrictions (single character I/O) [the 8<sup>th</sup> line with the
three <big>'''say'''</big><small>s</small>].
<br>This displaying of informative messages is only to help the observer to know what is being performed.
No recursion or the stack is used. The program could've been written without subroutines.
<lang rexx>/*REXX program
do case=1 for 2; #= 0 /*#: is the number of characters read.*/
say; say; say '════════ reading file: ' iFID "════════" /* ◄■■■■■■■■■ optional. */
do until x==.
do until \
call readChar
call readLetters;
if \datatype(x, 'M') then leave /*Found punctuation? Then leave J. */
call readLetters; call writeChar; #=punct /*read/write letters; new location*/▼
call writeChar /*write a character (which is a letter)*/
end /*j*/ /* [↑] perform for "even" words. */
call readLetters /*read a letter (and maybe punctuation)*/
▲ call
end /*until x==.*/
end /*case*/
exit /*stick a fork in it, we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
readChar: if arg(1)=='' then do; x= charin(iFID); #= #+1; end /*read
else x= charin(iFID, arg(1) ) /* " specific
return</lang>
:* input file '''ODDWORD.IN1''' ───► <tt> what,is,the;meaning,of:life. </tt>
:* input file '''ODDWORD.IN2''' ───► <tt> we,are;not,in,kansas;any,more. </tt>
|