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. Conversion from int to string

Conversion from int to string

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++tutorial
3 Posts 3 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.
  • G Offline
    G Offline
    gls2ro
    wrote on last edited by
    #1

    HELLO! PLEASE HELP ME! I'm new in C/C++ programming. And i have a problem: here is the code: char ch=fgetc(filein); char s[20]=""; Now what I want is to put in string s the value that is the ord(c). Example:if c is 'a' then I want put in s value "97". This part of my code is written in ANSI/C language. How can I do this? Thank you very much!

    R D 2 Replies Last reply
    0
    • G gls2ro

      HELLO! PLEASE HELP ME! I'm new in C/C++ programming. And i have a problem: here is the code: char ch=fgetc(filein); char s[20]=""; Now what I want is to put in string s the value that is the ord(c). Example:if c is 'a' then I want put in s value "97". This part of my code is written in ANSI/C language. How can I do this? Thank you very much!

      R Offline
      R Offline
      Rage
      wrote on last edited by
      #2

      I assume that ord(c) should return you the ASCII value of char c (maybe I misunderstand you). Therefore,

      char c = 'a';

      is equivalent to

      char c = 97; // here i'm not sure about the ascii value, might not be 97

      Then to get a string like "97", I would recommend using sprintf, as explained in Mike's FAQ on this link.

      sprintf ( s, "%d", c );

      Hope this helps. ~RaGE();

      1 Reply Last reply
      0
      • G gls2ro

        HELLO! PLEASE HELP ME! I'm new in C/C++ programming. And i have a problem: here is the code: char ch=fgetc(filein); char s[20]=""; Now what I want is to put in string s the value that is the ord(c). Example:if c is 'a' then I want put in s value "97". This part of my code is written in ANSI/C language. How can I do this? Thank you very much!

        D Offline
        D Offline
        dairiseky
        wrote on last edited by
        #3

        I am quite a beginner myself, but I think u can use pointers to do this. Something like: char *ptrs=NULL; char s[20]="a, c, d, f, l, m"; ptrs=&s[3];//pointer points le address of s[3] printf(" %d\n", s[3]);//should print the address *ptrs=63; //value of pointer is 63 printf(" %d\n", s[3]);//should print 63 I think this is not correct, but might give you ideas. :doh: THX

        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