Thread: Putchar() to print an integer value?

  1. #1
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688

    Putchar() to print an integer value?

    Ok, I swear my book is wrong here.

    Code:
    int main ( void )
    {
       int amount = 65;
       
       printf("Value of amount %d", amount);
       printf("\n");
    	putchar( 65 ); /*putchar prints the character value of an entered integer*/
    
       return 0;
    }
    The above is correct, as function putchar() takes integer 65 and prints A as its character equivelent. But then the book asks me to re-write the above as an exercise so putchar prints the value stored in integer variable amount. I was always told putchar cannot output integers, it can olnly read them in and then translate them to the character value. Is my book wrong here?
    Double Helix STL

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    hmm... perhaps the idea is to get you to convert 65 to '6' and '5' and putchar() those?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    Could be right, Il give that a go. Thanks laserlight.
    Double Helix STL

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. struct pointer
    By t014y in forum C Programming
    Replies: 5
    Last Post: 01-26-2009, 03:50 PM
  2. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 10:43 AM
  3. Help with homework please
    By vleonte in forum C Programming
    Replies: 20
    Last Post: 10-13-2003, 11:16 AM
  4. What kind of programs should I start writing?
    By Macabre in forum C++ Programming
    Replies: 23
    Last Post: 04-12-2003, 08:13 PM
  5. Replies: 1
    Last Post: 07-31-2002, 11:35 AM