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. pointer to an array... "char"

pointer to an array... "char"

Scheduled Pinned Locked Moved C / C++ / MFC
helpdata-structuresquestion
9 Posts 5 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.
  • S Offline
    S Offline
    SilverShalkin
    wrote on last edited by
    #1

    ok, this is my code: char ID::SetID(char SID[11]) { char *pID[11]; char SSID[11]; pID = &SSID; *pID = SID; strcpy(&M_ID, SSID); return 0; } //i got my code to work with one character, now i want to make it work with more like 10 :) i have one problem "yet again" and it deals with the line: pID = &SSID; //i dont understand my error. this is the error: error C2440: '=' : cannot convert from 'char (*)[11]' to 'char *[11]' what does (*) mean, and: is there another way to declare a pointer to point to somthing? Thanks for your help! ~SilverShalkin

    S C O 3 Replies Last reply
    0
    • S SilverShalkin

      ok, this is my code: char ID::SetID(char SID[11]) { char *pID[11]; char SSID[11]; pID = &SSID; *pID = SID; strcpy(&M_ID, SSID); return 0; } //i got my code to work with one character, now i want to make it work with more like 10 :) i have one problem "yet again" and it deals with the line: pID = &SSID; //i dont understand my error. this is the error: error C2440: '=' : cannot convert from 'char (*)[11]' to 'char *[11]' what does (*) mean, and: is there another way to declare a pointer to point to somthing? Thanks for your help! ~SilverShalkin

      S Offline
      S Offline
      soptest
      wrote on last edited by
      #2

      if pSID is NUL terminated string then code is:

      char ID::SetID(char *pSID)
      {
      strcpy(&M_ID, pSID);
      return 0;
      }

      if pSID array of char then code is:

      char ID::SetID(char *pSID, int isize = 10)
      {
      //default size of id is 10 chars, or what ever you want
      memcpy(&M_ID, pSID, isize);
      return 0;
      }

      soptest

      1 Reply Last reply
      0
      • S SilverShalkin

        ok, this is my code: char ID::SetID(char SID[11]) { char *pID[11]; char SSID[11]; pID = &SSID; *pID = SID; strcpy(&M_ID, SSID); return 0; } //i got my code to work with one character, now i want to make it work with more like 10 :) i have one problem "yet again" and it deals with the line: pID = &SSID; //i dont understand my error. this is the error: error C2440: '=' : cannot convert from 'char (*)[11]' to 'char *[11]' what does (*) mean, and: is there another way to declare a pointer to point to somthing? Thanks for your help! ~SilverShalkin

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

        You would do better to use std::string instead of char arrays. Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002

        N 1 Reply Last reply
        0
        • C Christian Graus

          You would do better to use std::string instead of char arrays. Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002

          N Offline
          N Offline
          Nish Nishant
          wrote on last edited by
          #4

          Christian Graus wrote: You would do better to use std::string instead of char arrays. Is this an automated reply to any query on using char*s or CStrings? Nish :-)


          Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

          C 1 Reply Last reply
          0
          • N Nish Nishant

            Christian Graus wrote: You would do better to use std::string instead of char arrays. Is this an automated reply to any query on using char*s or CStrings? Nish :-)


            Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

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

            char*, yes. CString or _bstr_t, no. std::string is not as complete as it could be, I use it where it does all I need, otherwise I reach for one of the other string classes, ( although we do not use MFC here ), but I would pretty much never use a char *. Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002

            N 1 Reply Last reply
            0
            • C Christian Graus

              char*, yes. CString or _bstr_t, no. std::string is not as complete as it could be, I use it where it does all I need, otherwise I reach for one of the other string classes, ( although we do not use MFC here ), but I would pretty much never use a char *. Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002

              N Offline
              N Offline
              Nish Nishant
              wrote on last edited by
              #6

              Christian Graus wrote: I reach for one of the other string classes, ( although we do not use MFC here ), non-MFC and non-STL string classes??? ATL? Nish


              Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

              C 1 Reply Last reply
              0
              • N Nish Nishant

                Christian Graus wrote: I reach for one of the other string classes, ( although we do not use MFC here ), non-MFC and non-STL string classes??? ATL? Nish


                Regards, Nish Native CPian. Born and brought up on CP. With the CP blood in him.

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

                _bstr_t wraps a BSTR and a char *, so they are interchangable. CComBSTR is a BSTR wrapper. Both are used in COM, but I don't think they are specific to ATL. We have a class derived from std::string called CString which does a lot of what the MFC one does. ( Yes, I know you should not derive from std::string, I was not here when they did it ). Christian The tragedy of cyberspace - that so much can travel so far, and yet mean so little. And you don't spend much time with the opposite sex working day and night, unless the pizza delivery person happens to be young, cute, single and female. I can assure you, I've consumed more than a programmer's allotment of pizza, and these conditions have never aligned. - Christopher Duncan - 18/04/2002

                1 Reply Last reply
                0
                • S SilverShalkin

                  ok, this is my code: char ID::SetID(char SID[11]) { char *pID[11]; char SSID[11]; pID = &SSID; *pID = SID; strcpy(&M_ID, SSID); return 0; } //i got my code to work with one character, now i want to make it work with more like 10 :) i have one problem "yet again" and it deals with the line: pID = &SSID; //i dont understand my error. this is the error: error C2440: '=' : cannot convert from 'char (*)[11]' to 'char *[11]' what does (*) mean, and: is there another way to declare a pointer to point to somthing? Thanks for your help! ~SilverShalkin

                  O Offline
                  O Offline
                  Orbital
                  wrote on last edited by
                  #8

                  Hi! The char *pID[11] declare an array of 11 pointers to char The char SSID[11] declare an array of 11 char So I think you mean char (*pID)[11] Anyway you can not do *pID=SID because *pID is not a l-value so you have to use a function like memcopy ... or strcopy if it is a string Bye, Orbital^ ...the night is long ... but not long enought to do some real coding ...

                  S 1 Reply Last reply
                  0
                  • O Orbital

                    Hi! The char *pID[11] declare an array of 11 pointers to char The char SSID[11] declare an array of 11 char So I think you mean char (*pID)[11] Anyway you can not do *pID=SID because *pID is not a l-value so you have to use a function like memcopy ... or strcopy if it is a string Bye, Orbital^ ...the night is long ... but not long enought to do some real coding ...

                    S Offline
                    S Offline
                    SilverShalkin
                    wrote on last edited by
                    #9

                    Orbital^ wrote: Anyway you can not do *pID=SID because *pID is not a l-value so you have to use a function like memcopy ... or strcopy if it is a string that makes more sense! so everything dealing with arrays, do not set equal, yet, strcpy() and memcpy()? i'll look through some more things, and try it again! Thanks everybody! i alos will check out std::string :) ~SilverShalkin :rose:

                    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