Odd word problem: Difference between revisions
Content added Content deleted
m (→{{header|REXX}}: split compound statements, used a template for the output section, simplified the code.) |
m (→{{header|REXX}}: simplified the program, changed some comments.) |
||
Line 2,281: | Line 2,281: | ||
do until x==. /* [↓] perform until reaching a period*/ |
do until x==. /* [↓] perform until reaching a period*/ |
||
do until \datatype(x, 'M') /* [↓] " " punctuation found*/ |
do until \datatype(x, 'M') /* [↓] " " punctuation found*/ |
||
call |
call rChar /*read a single character. */ |
||
call |
call wChar /*write " " " */ |
||
end /*until \data···*/ /* [↑] read/write until punctuation. */ |
end /*until \data···*/ /* [↑] read/write until punctuation. */ |
||
if x==. then leave /*is this the end─of─sentence (period)?*/ |
if x==. then leave /*is this the end─of─sentence (period)?*/ |
||
call readLetters; punct= # /*save the location of the punctuation.*/ |
call readLetters; punct= # /*save the location of the punctuation.*/ |
||
do j=#-1 by -1 /*read some characters backwards. */ |
do j=#-1 by -1 /*read some characters backwards. */ |
||
call |
call rChar j /*read previous word (backwards). */ |
||
if \datatype(x, 'M') then leave /*Found punctuation? Then leave J. */ |
if \datatype(x, 'M') then leave /*Found punctuation? Then leave J. */ |
||
call |
call wChar /*write a character (which is a letter)*/ |
||
end /*j*/ /* [↑] perform for "even" words. */ |
end /*j*/ /* [↑] perform for "even" words. */ |
||
call |
call rLett /*read a letter (and maybe punctuation)*/ |
||
call |
call wChar; #= punct /*write a char; punctuation location. */ |
||
end /*until x==.*/ |
end /*until x==.*/ |
||
end /*case*/ /* [↑] process both of the input files*/ |
end /*case*/ /* [↑] process both of the input files*/ |
||
exit /*stick a fork in it, we're all done. */ |
exit /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
rLett: do until \datatype(x, 'M'); call rChar; end; return |
|||
wChar: call charout , x /*console*/; call charout oFID, x /*file*/; return |
|||
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
/*──────────────────────────────────────────────────────────────────────────────────────*/ |
||
rChar: if arg()==0 then do; x= charin(iFID); #= #+1; end /*read next char*/ |
|||
else x= charin(iFID, arg(1) ); /* " specific " */ return</lang> |
|||
return</lang> |
|||
{{out|output|text= when using the two (default) input files which contain:}} |
{{out|output|text= when using the two (default) input files which contain:}} |
||
:* input file '''ODDWORD.IN1''' ───► <tt> what,is,the;meaning,of:life. </tt> |
:* input file '''ODDWORD.IN1''' ───► <tt> what,is,the;meaning,of:life. </tt> |