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. Convertions ??

Convertions ??

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelpquestion
8 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.
  • P Offline
    P Offline
    Programm3r
    wrote on last edited by
    #1

    Hi all, Im trying the following, I have a character pointer and a char array, I'm trying to assing the value of the pointer to the array, with no luck, please help??

    char* variable = "what ever";
    functionExample(variable);

    void functionExample(char* variable)
    {
    char Value[] = variable;
    }

    Thanx in advance ....

    Only programmers that are better than C programmers are those who code in 1's and 0's..... :) :) Programm3r

    C A 2 Replies Last reply
    0
    • P Programm3r

      Hi all, Im trying the following, I have a character pointer and a char array, I'm trying to assing the value of the pointer to the array, with no luck, please help??

      char* variable = "what ever";
      functionExample(variable);

      void functionExample(char* variable)
      {
      char Value[] = variable;
      }

      Thanx in advance ....

      Only programmers that are better than C programmers are those who code in 1's and 0's..... :) :) Programm3r

      C Offline
      C Offline
      Chris Losinger
      wrote on last edited by
      #2

      Programm3r wrote:

      char Value[] = variable;

      that is not legal C++. the easiest way to do this is with a string class of some kind:

      CString Value = variable;

      or

      std::string Value = variable;

      or, if you have to use a char array:

      int iLen = strlen(variable);
      char Value = new char [ iLen + 1 ];
      strcpy(Value, variable);
      Value[iLen] = 0;

      ...

      delete [] Value;

      image processing | blogging

      P 1 Reply Last reply
      0
      • C Chris Losinger

        Programm3r wrote:

        char Value[] = variable;

        that is not legal C++. the easiest way to do this is with a string class of some kind:

        CString Value = variable;

        or

        std::string Value = variable;

        or, if you have to use a char array:

        int iLen = strlen(variable);
        char Value = new char [ iLen + 1 ];
        strcpy(Value, variable);
        Value[iLen] = 0;

        ...

        delete [] Value;

        image processing | blogging

        P Offline
        P Offline
        Programm3r
        wrote on last edited by
        #3

        O.K ... Thanx for the response ... But why do I always get this error, I mean I am using:

        using namespace std;
        
        error C2065: 'CString' : undeclared identifier
        

        :confused::sigh:

        Only programmers that are better than C programmers are those who code in 1's and 0's..... :) :) Programm3r

        T 1 Reply Last reply
        0
        • P Programm3r

          O.K ... Thanx for the response ... But why do I always get this error, I mean I am using:

          using namespace std;
          
          error C2065: 'CString' : undeclared identifier
          

          :confused::sigh:

          Only programmers that are better than C programmers are those who code in 1's and 0's..... :) :) Programm3r

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #4

          CString is not the STL std::string class. it comes from MFC.


          TOXCCT >>> GEII power

          [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

          P 1 Reply Last reply
          0
          • T toxcct

            CString is not the STL std::string class. it comes from MFC.


            TOXCCT >>> GEII power

            [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

            P Offline
            P Offline
            Programm3r
            wrote on last edited by
            #5

            Thanx ... cause otherwise I would have wasted my life trying to figure out how to make that CString work.... :) X|

            Only programmers that are better than C programmers are those who code in 1's and 0's..... :) :) Programm3r

            T 1 Reply Last reply
            0
            • P Programm3r

              Thanx ... cause otherwise I would have wasted my life trying to figure out how to make that CString work.... :) X|

              Only programmers that are better than C programmers are those who code in 1's and 0's..... :) :) Programm3r

              T Offline
              T Offline
              toxcct
              wrote on last edited by
              #6

              couldn't you just search the MSDN[^] ... ? ;P


              TOXCCT >>> GEII power

              [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

              P 1 Reply Last reply
              0
              • T toxcct

                couldn't you just search the MSDN[^] ... ? ;P


                TOXCCT >>> GEII power

                [VisualCalc 3.0  updated ][Flags Beginner's Guide  new! ]

                P Offline
                P Offline
                Programm3r
                wrote on last edited by
                #7

                It was a joke.... :laugh::laugh: As if my world would end because of CString .... :) :)

                Only programmers that are better than C programmers are those who code in 1's and 0's..... :) :) Programm3r

                1 Reply Last reply
                0
                • P Programm3r

                  Hi all, Im trying the following, I have a character pointer and a char array, I'm trying to assing the value of the pointer to the array, with no luck, please help??

                  char* variable = "what ever";
                  functionExample(variable);

                  void functionExample(char* variable)
                  {
                  char Value[] = variable;
                  }

                  Thanx in advance ....

                  Only programmers that are better than C programmers are those who code in 1's and 0's..... :) :) Programm3r

                  A Offline
                  A Offline
                  Ahmed Ismail Mohamed
                  wrote on last edited by
                  #8

                  hello! All i want to ask about a modifiction of the below line i want to know is it right or wrong and why?

                  Programm3r wrote:

                  char Value[] = variable;

                  first:Programm3r has made a mistake here that he assigned a value var to a pointer. second: i think it may be char value[]; &value[0] = variable; thanks for your reply

                  ****************** ****************** ** Ahmed Ismail ** ****************** ******************

                  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