Thread: atoi question?

  1. #1
    Registered User
    Join Date
    Jan 2005

    atoi question?


    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,

  2. #2
    Registered User cbastard's Avatar
    Join Date
    Jul 2005
    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

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

    All makes sense now, thankyou!

  4. #4
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005

    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:

    My website:
    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-22-2009, 11:55 PM
  2. atoi related question
    By The Gweech in forum C++ Programming
    Replies: 2
    Last Post: 10-01-2003, 11:14 PM
  3. Question...
    By TechWins in forum A Brief History of
    Replies: 16
    Last Post: 07-28-2003, 09: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
    Replies: 5
    Last Post: 12-24-2001, 01:47 AM