Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.swapon.de!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail From: Keith Thompson Newsgroups: comp.lang.c Subject: Re: strtoll discussion Date: Fri, 03 Apr 2015 15:08:09 -0700 Organization: None to speak of Lines: 31 Message-ID: <87iodcyieu.fsf@kst-u.example.com> References: <8a9be12a-e6c6-4cfe-8187-4e4f9db5a1f0@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Injection-Info: mx02.eternal-september.org; posting-host="9be37d943435275679235b07c7947eef"; logging-data="20205"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/EYGnZbu2w5vDGeTUSMOTN" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:flO+ESp1Nev5o8LxRbzTjYmS+mg= sha1:75zkkBK2jMkPgtCRaCAYhIPsjwY= Xref: csiph.com comp.lang.c:59562 Richard Heathfield writes: > On 03/04/15 22:34, jacobnavia wrote: >> Le 03/04/2015 22:09, asetofsymbols@gmail.com a écrit : >>> Erm, at the risk of being picky, shouldn't line 14 be >>> else if (*str == '+') str ++; >> >> Yes! >> >> Thanks I will correct that ASAP. > > Also it would do no real harm to adopt the suggestion by > asetofsymbols@gmail.com to terminate Atoi's conversion when you run > out of digits, rather than when you run out of string: > > while(isdigit(*str)) instead of while(*str) would do it. I could go either way on that. The presented Atoi() function is deliberately quick and dirty, with no error checking. The document acknowledges this, saying that Atoi("ggg") returns 6105. It's just a starting point, showing how to add error checking in later revisions. It does jump directly from the quick-and-dirty Atoi() to the standard strto*() functions. Showing incremental improvements to Atoi() might be instructive, but it's not clear that it's worth the space. I suppose it depends on the intended audience. -- Keith Thompson (The_Other_Keith) kst-u@mib.org Working, but not speaking, for JetHead Development, Inc. "We must do something. This is something. Therefore, we must do this." -- Antony Jay and Jonathan Lynn, "Yes Minister"