managing char arrays
-
How can I convert a string to an ASCII value and then store it in an element of a char array? For example, I'd like the 30 to be stored in element[18] of the array. This is what I have. Thanks! char array[20]; array = "Supernatural"; CString str = "40"; strcpy(array[18],str); error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
-
How can I convert a string to an ASCII value and then store it in an element of a char array? For example, I'd like the 30 to be stored in element[18] of the array. This is what I have. Thanks! char array[20]; array = "Supernatural"; CString str = "40"; strcpy(array[18],str); error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
You can't. It's not possible to store a string as an element in a character array. Maybe what you're looking for is an array of char * ? Regards Senthil _____________________________ My Blog | My Articles | WinMacro
-
You can't. It's not possible to store a string as an element in a character array. Maybe what you're looking for is an array of char * ? Regards Senthil _____________________________ My Blog | My Articles | WinMacro
-
You can't. It's not possible to store a string as an element in a character array. Maybe what you're looking for is an array of char * ? Regards Senthil _____________________________ My Blog | My Articles | WinMacro
Yes, I do have an array of characters. I need to convert the ASCII value which is currently a string value to an ASCII character. Then store that ASCII character into the 18th element of the array. How do I go about doing that?
-
How can I convert a string to an ASCII value and then store it in an element of a char array? For example, I'd like the 30 to be stored in element[18] of the array. This is what I have. Thanks! char array[20]; array = "Supernatural"; CString str = "40"; strcpy(array[18],str); error C2664: 'strcpy' : cannot convert parameter 1 from 'char' to 'char *'
elephantstar wrote: array = "Supernatural"; What is this, other than a syntax error? If you want
array
to contain the string literal, use either of:char array[20] = "Supernatural";
...
char array[20];
strcpy(array, "Supernatural");elephantstar wrote: strcpy(array[18],str); The error message tells you exactly what the problem is.
array[18]
is achar
, but the first parameter ofstrcpy()
is supposed to be achar*
. Why are you usingchar
in such a fashion? If this is an MFC application, useCString
. Mixing the two types is seldom necessary.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
Yes, I do have an array of characters. I need to convert the ASCII value which is currently a string value to an ASCII character. Then store that ASCII character into the 18th element of the array. How do I go about doing that?
Are you talking about this:
CString str = "40";
array[18] = atoi(str);
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
yes he can.
CString
class provides aLPTSTR
cast operator... so usingstrcpy()
is possible as it uses this way 2 char arrays...
TOXCCT >>> GEII power
[toxcct][VisualCalc]No he can't :). It's not possible to store a string as an element in an array of characters. From what I understood, the OP wants to do this
char arr[20] = "Senthil";
arr[5] = "Kumar";which isn't logically possible. Regards Senthil _____________________________ My Blog | My Articles | WinMacro
-
elephantstar wrote: array = "Supernatural"; What is this, other than a syntax error? If you want
array
to contain the string literal, use either of:char array[20] = "Supernatural";
...
char array[20];
strcpy(array, "Supernatural");elephantstar wrote: strcpy(array[18],str); The error message tells you exactly what the problem is.
array[18]
is achar
, but the first parameter ofstrcpy()
is supposed to be achar*
. Why are you usingchar
in such a fashion? If this is an MFC application, useCString
. Mixing the two types is seldom necessary.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
I want to store the value of CString str into the array. vtValue.ChangeType(VT_BSTR); str = (LPCSTR)((_bstr_t)vtValue.bstrVal); Then I want to store the exact same data type into array[18]. Yes, it is an MFC application. I'm using char so that I can manipulate the data in each element easily.
-
I want to store the value of CString str into the array. vtValue.ChangeType(VT_BSTR); str = (LPCSTR)((_bstr_t)vtValue.bstrVal); Then I want to store the exact same data type into array[18]. Yes, it is an MFC application. I'm using char so that I can manipulate the data in each element easily.
elephantstar wrote: vtValue.ChangeType(VT_BSTR); str = (LPCSTR)((_bstr_t)vtValue.bstrVal); What's with all of the
BSTR
andVARIANT
stuff? Is this part of the original problem? elephantstar wrote: I'm using char so that I can manipulate the data in each element easily.CString
objects can be manipulated just as easily.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
elephantstar wrote: vtValue.ChangeType(VT_BSTR); str = (LPCSTR)((_bstr_t)vtValue.bstrVal); What's with all of the
BSTR
andVARIANT
stuff? Is this part of the original problem? elephantstar wrote: I'm using char so that I can manipulate the data in each element easily.CString
objects can be manipulated just as easily.
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
Sorry, I should have included the rest of the code. I'm using ADO to query some values. CString str, str2; _variant_t vtValue; vtValue = t_Rec->Fields->GetItem("NAME")->GetValue(); vtValue.ChangeType(VT_BSTR); str = (LPCSTR)((_bstr_t)vtValue.bstrVal); Instead of using char array[20], you're suggesting I just work with CString then. But if I do use CString, the following code fails. What am I doing wrong? Thanks.
vtValue = t_Rec->Fields->GetItem("NUMBER")->GetValue();
vtValue.ChangeType(VT_BSTR);
str2 = (LPTSTR)((_bstr_t)vtValue.bstrVal);
char x;
x = atoi(str2);
str.GetAt(18, str2); ///Debug Assertion Failed -
Sorry, I should have included the rest of the code. I'm using ADO to query some values. CString str, str2; _variant_t vtValue; vtValue = t_Rec->Fields->GetItem("NAME")->GetValue(); vtValue.ChangeType(VT_BSTR); str = (LPCSTR)((_bstr_t)vtValue.bstrVal); Instead of using char array[20], you're suggesting I just work with CString then. But if I do use CString, the following code fails. What am I doing wrong? Thanks.
vtValue = t_Rec->Fields->GetItem("NUMBER")->GetValue();
vtValue.ChangeType(VT_BSTR);
str2 = (LPTSTR)((_bstr_t)vtValue.bstrVal);
char x;
x = atoi(str2);
str.GetAt(18, str2); ///Debug Assertion Failedelephantstar wrote: str.GetAt(18, str2); ///Debug Assertion Failed This must be .Net as the
CString::GetAt()
method that comes with VC++ v6 only takes one parameter. In any case, what line of what file is firing the assertion?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
-
elephantstar wrote: str.GetAt(18, str2); ///Debug Assertion Failed This must be .Net as the
CString::GetAt()
method that comes with VC++ v6 only takes one parameter. In any case, what line of what file is firing the assertion?
"One must learn from the bite of the fire to leave it alone." - Native American Proverb
Nevermind. I went back to using char and it works just fine. Thanks Dave! Your help is always appreciated.
-
No he can't :). It's not possible to store a string as an element in an array of characters. From what I understood, the OP wants to do this
char arr[20] = "Senthil";
arr[5] = "Kumar";which isn't logically possible. Regards Senthil _____________________________ My Blog | My Articles | WinMacro