Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

function that reads an ascii char string and returns the int value

runtime string ascii

  • Please log in to reply
3 replies to this topic

#1 joninty

joninty

    CC Lurker

  • Just Joined
  • Pip
  • 5 posts

Posted 10 March 2010 - 08:12 AM

How would I write a function that reads an ascii char string and returns the int value that it represents. ignoring leading whitespace and stop conversion at the first non digit character. If it is not possible, the function should return 0 and indicate an error condition.
I cant use runtime library routines such as “scanf”.
Cheers,
Jo
  • 0

#2 bobdark

bobdark

    CC Addict

  • Just Joined
  • PipPipPipPipPip
  • 155 posts

Posted 10 March 2010 - 08:50 AM

Well that depends on what you CAN use. So what can you use??
  • 0

#3 WingedPanther73

WingedPanther73

    A spammer's worst nightmare

  • Moderator
  • 17757 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others

Posted 10 March 2010 - 12:33 PM

Is this in C or C++? Do you have access to the atoi() function?
  • 0

Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

My MineCraft server site: http://banishedwings.enjin.com/


#4 dargueta

dargueta

    I chown trolls.

  • Moderator
  • 4854 posts
  • Programming Language:C, Java, C++, PHP, Python, JavaScript, Perl, Assembly, Bash, Others
  • Learning:Objective-C

Posted 11 March 2010 - 12:56 AM

Hint: In ASCII, the characters '0' to '9' are consecutive. So if you were to subtract...
  • 0

sudo rm -rf / && echo $'Sanitize your inputs!'






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download