Re: String to Integer

From: George (greerga@DRAGON.HAM.MUOHIO.EDU)
Date: 10/01/97


On Wed, 1 Oct 1997, Akuma/Chris Baggett/DOOMer wrote:

>>heh, speaking of this, has anyone implemented a way to convert
>>a  , separated number to an integer/long?
>>like
>>
>>aCtoi("1,234,567") = 1234567

int aCtoi(char *txt)
{
  int i, c;

  /* Run through stripping ,'s */
  for (i = 0, c = 0; i < strlen(txt); i++)
    if (txt[i] != ',')
      txt[n++] = txt[i];
  /* NULL out excess characters. */
  txt[n] = '\0';
  /* Yeah I'm cheap. */
  return atoi(txt);
}

Standard mailer code disclaimer, but you get the idea. :)

--
George Greer  -  Me@Null.net   | Genius may have its limitations, but stupidity
http://www.van.ml.org/~greerga | is not thus handicapped. -- Elbert Hubbard


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     | http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/08/00 PST