Comma quibbling: Difference between revisions

Content added Content deleted
No edit summary
(Added solution for Action!)
Line 223: Line 223:
{ABC and DEF}
{ABC and DEF}
{ABC, DEF, G and H}</pre>
{ABC, DEF, G and H}</pre>

=={{header|Action!}}==
<lang Action!>PROC Append(CHAR ARRAY text,suffix)
BYTE POINTER srcPtr,dstPtr
BYTE len

len=suffix(0)
IF text(0)+len>255 THEN
len=255-text(0)
FI
IF len THEN
srcPtr=suffix+1
dstPtr=text+text(0)+1
MoveBlock(dstPtr,srcPtr,len)
text(0)==+suffix(0)
FI
RETURN

PROC Quibble(CARD ARRAY items INT count CHAR ARRAY result)
INT i

result(0)=0
Append(result,"(")
FOR i=0 TO count-1
DO
Append(result,items(i))
IF i=count-2 THEN
Append(result," and ")
ELSEIF i<count-2 THEN
Append(result,", ")
FI
OD
Append(result,")")
RETURN

PROC Test(CARD ARRAY items BYTE count)
CHAR ARRAY result(256)

Quibble(items,count,result)
PrintE(result)
RETURN

PROC Main()
CARD ARRAY items(5)

Test(items,0)

items(0)="ABC"
Test(items,1)

items(1)="DEF"
Test(items,2)

items(2)="G"
Test(items,3)

items(3)="H"
Test(items,4)
RETURN</lang>
{{out}}
[https://gitlab.com/amarok8bit/action-rosetta-code/-/raw/master/images/Comma_quibbling.png Screenshot from Atari 8-bit computer]
<pre>
()
(ABC)
(ABC and DEF)
(ABC, DEF and G)
(ABC, DEF, G and H)
</pre>


=={{header|Ada}}==
=={{header|Ada}}==