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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. function to convert char to char*

function to convert char to char*

Scheduled Pinned Locked Moved C / C++ / MFC
c++
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.
  • W Offline
    W Offline
    With_problem
    wrote on last edited by
    #1

    is there any function in vc++ to convert char to char* Thank you

    S C 2 Replies Last reply
    0
    • W With_problem

      is there any function in vc++ to convert char to char* Thank you

      S Offline
      S Offline
      Stephen Hewitt
      wrote on last edited by
      #2

      & e.g. char ch = 'a'; char *pChar = &ch; Be aware that when ch goes out of scope pChar is no longer valid.

      Steve

      1 Reply Last reply
      0
      • W With_problem

        is there any function in vc++ to convert char to char* Thank you

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        If you have a char, as in char c = 'a'; then you can get the address with &c. However, there's a problem. All the things I can think you'd want to use a char * for, assuming that the char * is a valid string until it hits a null. So, you need to do this: char * cp = new char[2]; cp[0] = c; cp[1] = NULL; Then you have a pointer to a string of one character length. Overall, you'd do better to use std::string.

        Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog

        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