Thread: Input polynomial, convert to function.

  1. #16
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    There is nothing you could have possibly read that confirms that ASCII 0-9 corresponds to the characters 0 through 9. The digits live in characters 48 through 57, so yes '2' is 50.

  2. #17
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Yes, very much because 50 is the ascii code for 2 - since you are taking "polynomial[0]" without converting it to an integer. In a trivial case where it's just one digit, you can usbtract '0' from the character, and you get the right value. But for completeness, you will probably want to use strtol (for "long int") or strtod (for "double"). These functions will also auotmatically tell you where the finished reading from the string, so you can use that to find where your next term starts (e.g. x in "x^2").

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #18
    Registered User
    Join Date
    Oct 2008
    Posts
    110
    Thanks both.

    tabstop: I actually misread this page: http://www.ssi-developer.net/reference/ascii-0.shtml, but then soon after looked at the wiki and realised.

    matsp: I also read up on how polynoimal[i] would return the ascii value and not the actual digit mcontained in the char, and since my last post I have my program well underway. Alot of it, I've just been writing,testing, writing, testing etc...and have also been optimizing a bit along the way, and overall I'm enjoying my c experience.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. About aes
    By gumit in forum C Programming
    Replies: 13
    Last Post: 10-24-2006, 03:42 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Replies: 3
    Last Post: 03-04-2005, 02:46 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 10:18 AM