Putchar function

This is a discussion on Putchar function within the C Programming forums, part of the General Programming Boards category; hey all, i am a newbie and will appreciate your help with this very beginners thread... i am trying to ...

  1. #1
    nyc
    nyc is offline
    Registered User
    Join Date
    Feb 2006
    Posts
    1

    Putchar function

    hey all,
    i am a newbie and will appreciate your help with this very beginners thread...
    i am trying to write a function that will accept an integer and will print it is ASCII value (after conversion) using putchar.
    here is what i have so far:
    Code:
    int my_itoa(int i)
    {
    putchar(i+'0');
    }
    however this function prints the value of i so if my argument was 3 it prints out 3.
    any idea how to get the ASCII value of 51?
    thanks a lot.

  2. #2
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,699
    no conversion is needed:

    putchar(51);

    that would print 3.
    Code:
    bool fun(bool value)
    {
        return std::pow(std::exp(1), std::complex<float>(0, 1) 
        * std::complex<float>(std::atan(1)*(1 << (value + 2))))
        .real() > 0;
    }

  3. #3
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    Code:
    putchar(i+'0');
    Since you were adding to the ascii value of 0 and since numbers are in the correct order in ascii that is why a value of 3 outputted the number 3 as 0+3=3

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  3. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  4. temperature sensors
    By danko in forum C Programming
    Replies: 22
    Last Post: 07-10-2007, 07:26 PM
  5. Replies: 28
    Last Post: 07-16-2006, 11:35 PM

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