atoi question?

This is a discussion on atoi question? within the C Programming forums, part of the General Programming Boards category; Hiya, I saw some code a while ago, the author needed a number to be input (to main). Instead of ...

  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    15

    atoi question?

    Hiya,

    I saw some code a while ago, the author needed a number to be input (to main).

    Instead of using a u_short and just assigning that to the optarg he used a u_char and then used atoi to convert to a number.

    Why would you do this? Sorry if this is an obtuse question!

    Many thank,
    Joe

  2. #2
    Registered User cbastard's Avatar
    Join Date
    Jul 2005
    Location
    India
    Posts
    167
    Input in main() or argv are strings.If you enter a number they are taken as strings so to convert them to numbers,he used atoi.
    Long time no C. I need to learn the language again.
    Help a man when he is in trouble and he will remember you when he is in trouble again.
    You learn in life when you lose.
    Complex problems have simple, easy to understand wrong answers.
    "A ship in the harbour is safe, but that's not what ships are built
    for"

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    15
    I see!

    All makes sense now, thankyou!

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Having trouble with atoi
    By NewbGuy in forum C Programming
    Replies: 2
    Last Post: 05-23-2009, 12:55 AM
  2. atoi related question
    By The Gweech in forum C++ Programming
    Replies: 2
    Last Post: 10-02-2003, 12:14 AM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 10:47 PM
  4. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21