Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. How to convert ASCII code to character [modified]

How to convert ASCII code to character [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
4 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mohsen Saad
    wrote on last edited by
    #1

    Hi All, I need to add the carriage return and line feed to a string to simulate the new line '\n' before writing it to a binary file. what is the function I can give the ASCII Code and it returns the equivalant character. What I need is a function that is similar to chr in Visual Basic -- modified at 8:17 Thursday 21st September, 2006

    K _ Z 3 Replies Last reply
    0
    • M Mohsen Saad

      Hi All, I need to add the carriage return and line feed to a string to simulate the new line '\n' before writing it to a binary file. what is the function I can give the ASCII Code and it returns the equivalant character. What I need is a function that is similar to chr in Visual Basic -- modified at 8:17 Thursday 21st September, 2006

      K Offline
      K Offline
      kakan
      wrote on last edited by
      #2

      Just write "\r\n" to the file (at the end of each line)

      Alcohol. The cause of, and the solution to, all of life's problems - Homer Simpson

      1 Reply Last reply
      0
      • M Mohsen Saad

        Hi All, I need to add the carriage return and line feed to a string to simulate the new line '\n' before writing it to a binary file. what is the function I can give the ASCII Code and it returns the equivalant character. What I need is a function that is similar to chr in Visual Basic -- modified at 8:17 Thursday 21st September, 2006

        _ Offline
        _ Offline
        _AnsHUMAN_
        wrote on last edited by
        #3

        Mohsen Saad wrote:

        Re: How to convert ASCII code to character

        int i=10;      //For Carriage return use 13
        char *str=new char[3];
        sprintf(str,"%c",i);
        cout<
        

        Somethings seem HARD to do, until we know how to do them. ;-)**_AnShUmAn_**

        1 Reply Last reply
        0
        • M Mohsen Saad

          Hi All, I need to add the carriage return and line feed to a string to simulate the new line '\n' before writing it to a binary file. what is the function I can give the ASCII Code and it returns the equivalant character. What I need is a function that is similar to chr in Visual Basic -- modified at 8:17 Thursday 21st September, 2006

          Z Offline
          Z Offline
          Zac Howland
          wrote on last edited by
          #4

          Mohsen Saad wrote:

          what is the function I can give the ASCII Code and it returns the equivalant character.

          There is no need for that in C++. The ASCII code IS the character. That is:

          char c1 = '\n'; // c1 = 10
          char c2 = '\r'; // c2 = 13
          

          If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups