string copy problem in structure variable
-
Hi! Need help to copy string in the structure variable . following is my structure, struct argument_list { WCHAR *pszInFile; WCHAR *pszOutFil; :confused: what should i have used here
string or char *?
:confused: char* Host; // Initially I had used string but strcpy function does not support to copy the string char* UserID; char* InitPackageRequest; char* ScriptFile; }; I have made this structure for the thread. to pass the parameter. for that i have used the following. struct argument_list *l; l=(argument_list *)malloc(sizeof(argument_list));`is lstrcpy require here?` l->pszInFile=bufferwithpath; l->pszOutFil=w_Output;
l->_ProtectSet=_ProtectSet; l->hList=hList; //l->Host(HOST); l->Host=NULL;strcpy(l->Host,HOST); //got error here
l->hwndEncrypt=hwndEncrypt; l->hWndinoutfiledir=hWndinoutfiledir; l->hwndParent=hDlg; l->InitPackageRequest=NULL; strcpy(l->InitPackageRequest,sINIT_PACKAGE_RESPONSE.c_str()); l->Port=PORT; l->ScriptFile=NULL; strcpy(l->ScriptFile,COMMUNICATOR_SCRIPT_FILE_PATH); l->UserID=NULL; strcpy(l->UserID,UserID.c_str());"Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India
-
Hi! Need help to copy string in the structure variable . following is my structure, struct argument_list { WCHAR *pszInFile; WCHAR *pszOutFil; :confused: what should i have used here
string or char *?
:confused: char* Host; // Initially I had used string but strcpy function does not support to copy the string char* UserID; char* InitPackageRequest; char* ScriptFile; }; I have made this structure for the thread. to pass the parameter. for that i have used the following. struct argument_list *l; l=(argument_list *)malloc(sizeof(argument_list));`is lstrcpy require here?` l->pszInFile=bufferwithpath; l->pszOutFil=w_Output;
l->_ProtectSet=_ProtectSet; l->hList=hList; //l->Host(HOST); l->Host=NULL;strcpy(l->Host,HOST); //got error here
l->hwndEncrypt=hwndEncrypt; l->hWndinoutfiledir=hWndinoutfiledir; l->hwndParent=hDlg; l->InitPackageRequest=NULL; strcpy(l->InitPackageRequest,sINIT_PACKAGE_RESPONSE.c_str()); l->Port=PORT; l->ScriptFile=NULL; strcpy(l->ScriptFile,COMMUNICATOR_SCRIPT_FILE_PATH); l->UserID=NULL; strcpy(l->UserID,UserID.c_str());"Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India
amitmistry_petlad wrote:
strcpy(l->Host,HOST); //got error here
You got an error because there is no memory associated with the 'Host' member - it's just a pointer. You must either: 1) allocate memory before the strcpy - for example, l->Host = malloc(...); OR you can change the struct to a specific size for the 'Host' member - for example, char Host[100]. You seem to be confused about the difference between a char* pointer (char *s), and an array of char's (s[100]). You can use either one in the strcpy() function, but if you want to use a pointer, be sure you know where the memory has been allocated.
-
amitmistry_petlad wrote:
strcpy(l->Host,HOST); //got error here
You got an error because there is no memory associated with the 'Host' member - it's just a pointer. You must either: 1) allocate memory before the strcpy - for example, l->Host = malloc(...); OR you can change the struct to a specific size for the 'Host' member - for example, char Host[100]. You seem to be confused about the difference between a char* pointer (char *s), and an array of char's (s[100]). You can use either one in the strcpy() function, but if you want to use a pointer, be sure you know where the memory has been allocated.
Thank you very much sir ! :) :rose:
"Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India
-
Hi! Need help to copy string in the structure variable . following is my structure, struct argument_list { WCHAR *pszInFile; WCHAR *pszOutFil; :confused: what should i have used here
string or char *?
:confused: char* Host; // Initially I had used string but strcpy function does not support to copy the string char* UserID; char* InitPackageRequest; char* ScriptFile; }; I have made this structure for the thread. to pass the parameter. for that i have used the following. struct argument_list *l; l=(argument_list *)malloc(sizeof(argument_list));`is lstrcpy require here?` l->pszInFile=bufferwithpath; l->pszOutFil=w_Output;
l->_ProtectSet=_ProtectSet; l->hList=hList; //l->Host(HOST); l->Host=NULL;strcpy(l->Host,HOST); //got error here
l->hwndEncrypt=hwndEncrypt; l->hWndinoutfiledir=hWndinoutfiledir; l->hwndParent=hDlg; l->InitPackageRequest=NULL; strcpy(l->InitPackageRequest,sINIT_PACKAGE_RESPONSE.c_str()); l->Port=PORT; l->ScriptFile=NULL; strcpy(l->ScriptFile,COMMUNICATOR_SCRIPT_FILE_PATH); l->UserID=NULL; strcpy(l->UserID,UserID.c_str());"Success lies not in the result , But in the efforts !!!!!" Amit Mistry - petlad -Gujarat-India
amit here