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