Thread: How to change an INT into a CHAR ??

  1. #1
    SublicK
    Guest

    How to change an INT into a CHAR ??

    How can you change an INT var into a CHAR var?

    thx

  2. #2
    Banned Troll_King's Avatar
    Join Date
    Oct 2001
    Posts
    1,784
    There is a certain range of integers that can be represented as ANSI characters. Do you want a variable that you can manipulate or do you just want to display the character value?

    If you want the variable, than after you have validated the integer, you can print it into a string (sprintf), than assign the character in the string to a char type.

    If you just want to display the character value of the integer than there are functions such as printf that can accomplish this by using the right control string specifier.

    I don't know if cout will act like a printf control string if you typecast the integer, it might.

    Consult an ANSI table.
    Last edited by Troll_King; 10-16-2001 at 12:52 PM.

  3. #3
    Unregistered
    Guest
    What kinds of control string specifiers are there?

  4. #4
    hamilton7
    Guest
    I just did this in one of my programs try this

    sprintf(oi,"%d",OI);//use sprintf to convert numbers to strings

  5. #5
    hamilton7
    Guest
    Sorry I forgot to tell you oi is a string and OI is an int

  6. #6
    SublicK
    Guest
    Thx

  7. #7
    Registered User
    Join Date
    Aug 2001
    Posts
    154
    To display an int as a corresponding ASCII character, you can use cout.put(x), where x is an int with a corresponding ASCII value. This doesn't actually change anything, but is fine for couts only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to combine these working parts??
    By transgalactic2 in forum C Programming
    Replies: 0
    Last Post: 02-01-2009, 08:19 AM
  2. Binary Search Trees Part III
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 10-02-2004, 03:00 PM
  3. Can't Find Conio.h?
    By drdroid in forum C++ Programming
    Replies: 27
    Last Post: 09-26-2002, 04:24 AM
  4. My graphics library
    By stupid_mutt in forum C Programming
    Replies: 3
    Last Post: 11-26-2001, 06:05 PM
  5. A Simple (?) Problem
    By Unregistered in forum C++ Programming
    Replies: 8
    Last Post: 10-12-2001, 04:28 AM