List:General Discussion« Previous MessageNext Message »
From:Dan Nelson Date:August 23 1999 3:50am
Subject:Re: trailing comma in delete statement
View as plain text  
In the last episode (Aug 22), Paul DuBois said:
> At 10:15 PM -0700 8/22/99, Mick Hanna wrote:
> >im calling a loop like so:
> >
> >printf("%s,",rmid[i]);
> 
> You have to know when you're printing the last item in your list,
> and don't print the trailing comma when you reach that item.

A better way is to _prepend_ the comma, but not for the first element:

    for (i = 0; i < numitems; i++)
    {
        printf("%s%s", (i > 0) ? "," : "", rmid[i]);
    }

That way the special case is the "first element?" case instead of the
"last element?" case.

-- 
	Dan Nelson
	dnelson@stripped
Thread
trailing comma in delete statementMick Hanna22 Aug
  • Re: trailing comma in delete statementMark Maggelet22 Aug
  • Re: trailing comma in delete statementJeff Urban22 Aug
    • Re: trailing comma in delete statementThimble Smith22 Aug
    • Re: trailing comma in delete statementScott Hess23 Aug
  • Re: trailing comma in delete statementPaul DuBois23 Aug
    • Re: trailing comma in delete statementDan Nelson23 Aug
      • Re: trailing comma in delete statementMichael Widenius27 Aug
Re: trailing comma in delete statementJesse22 Aug
  • Re: trailing comma in delete statementAlok K. Dhir22 Aug
Re: trailing comma in delete statementAnthony Mendoza23 Aug
  • Re: trailing comma in delete statementJames Manning23 Aug
Re: trailing comma in delete statementAnthony Mendoza23 Aug