Jump to content

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

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
3 replies to this topic

#1
joninty

joninty

    Newbie

  • Members
  • Pip
  • 5 posts
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

#2
bobdark

bobdark

    Programmer

  • Members
  • PipPipPipPip
  • 164 posts
Well that depends on what you CAN use. So what can you use??

#3
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
Is this in C or C++? Do you have access to the atoi() function?
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#4
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
Hint: In ASCII, the characters '0' to '9' are consecutive. So if you were to subtract...
sudo rm -rf /