Putchar() to print an integer value?

This is a discussion on Putchar() to print an integer value? within the C Programming forums, part of the General Programming Boards category; Ok, I swear my book is wrong here. Code: int main ( void ) { int amount = 65; printf("Value ...

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

    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?
    I'm just trying to be a better person - My Name Is Earl

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,796
    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,480
    Could be right, Il give that a go. Thanks laserlight.
    I'm just trying to be a better person - My Name Is Earl

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, 02:50 PM
  2. load gif into program
    By willc0de4food in forum Windows Programming
    Replies: 14
    Last Post: 01-11-2006, 09: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

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