• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: atoi()
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: atoi()


  • Subject: Re: atoi()
  • From: "Dr. H. Nikolaus Schaller" <email@hidden>
  • Date: Sun, 19 Jan 2003 12:38:51 +0100

You are welcome!
One thing I forgot is handling of negative numbers:
> int atoi(char *str) { int n=0; if(*str=='-') return -atoi(str+1);
> while(*str >='0' && *str <='9') n=10*n+(*str++-'0'); return n; }
Nikolaus

Am Sonntag, 19.01.03 um 01:38 Uhr schrieb Philip George:

> Now that's an answer I can sink my teeth into. Without the smoke and
> mirrors, it's easy to see that atoi() will always work, whether the
> API is pulled or not. Great idea.
>
> Thank you.
>
> - Philip
>
> quoted from digest ----------
>
> Hi,
> good idea to solve this discussion thread. To me it seems to need less
> typing effort to submit a one-liner (cited from memory from old K&R
> Standard C) than a discussion about libraries, standards, OS versions
> etc.:
>
> int atoi(char *str) { int n=0; while(*str >='0' && *str <='9')
> n=10*n+(*str++-'0'); return n; }
>
> This will work as long as the machine code can somehow be
> interpreted...
>
> Or try: sscanf(str, "%d", &i) instead of i=atoi(str)
>
> HNS
>
>
> -------------------------
>
>
+-------------------+
! email@hidden !
+-------------------+
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >atoi() (From: Philip George <email@hidden>)

  • Prev by Date: Re: NSCell subclass and startTracking
  • Next by Date: NSMatrix of NSView ?
  • Previous by thread: atoi()
  • Next by thread: Threaded NSConnection "listen"
  • Index(es):
    • Date
    • Thread