By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,159 Members | 980 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,159 IT Pros & Developers. It's quick & easy.

Converting String to Char Array

P: n/a
Hello,
I'm trying to convert String to Char array. I'm getting a string from
user input text box and then I have char firstName[size].
I need to convert the string that is in the text box to
firstName[size].
Thank you

Jul 23 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Al************@gmail.com wrote:
Hello,
I'm trying to convert String to Char array. I'm getting a string from
user input text box and then I have char firstName[size].
I need to convert the string that is in the text box to
firstName[size].
Thank you

strcpy(firstName, my_string.c_str());

provided you don't have any embedded nulls and you are sure firstName
is large enough.
Jul 23 '05 #2

P: n/a
if I use const char LastName[SC_PLYR_SIZEOF_LastName] here how I use
it:
strncpy( &headerbuf[SC_PLYR_OFFSET_LastName], (char *) LastName,
SC_PLYR_SIZEOF_LastName );
but now since i get the the Last Name from textbox as a String i'm not
sure how to do the strncpy
Thank you

Jul 23 '05 #3

P: n/a

<Al************@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
if I use const char LastName[SC_PLYR_SIZEOF_LastName] here how I use
it:
strncpy( &headerbuf[SC_PLYR_OFFSET_LastName], (char *) LastName,
SC_PLYR_SIZEOF_LastName );
but now since i get the the Last Name from textbox as a String i'm not
sure how to do the strncpy
Thank you

What's a "String"? There is a class called "string" in the std namespace
(from <string>), but nothing called "String". If you're using MFC, maybe
you mean "CString"? In that case, check out an MFC newsgroup (or Google)
for answers concerning that class. If String is a class defined by some
thrid party, check the documentation for that class's library. You've
already been given the answer if you're using the std:string class.

-Howard
Jul 23 '05 #4

P: n/a
Thank you. I was able to fix the problem. Here is what I did:
String* lName = LastNameTexBox->Text;
char* pString =
(char*)System::Runtime::InteropServices::Marshal:: StringToHGlobalAnsi(lName).ToPointer();

Jul 23 '05 #5

P: n/a

<Al************@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
Thank you. I was able to fix the problem. Here is what I did:
String* lName = LastNameTexBox->Text;
char* pString =
(char*)System::Runtime::InteropServices::Marshal:: StringToHGlobalAnsi(lName).ToPointer();


What the heck is that??? C#? It sure ain't anything from standard C++.
Methinks you're in the wrong newsgroup!
-Howard
Jul 23 '05 #6

P: n/a
Howard wrote:
Thank you. I was able to fix the problem. Here is what I did:
String* lName = LastNameTexBox->Text;
char* pString =
(char*)System::Runtime::InteropServices::Marshal ::StringToHGlobalAnsi(lName).ToPointer();

What the heck is that??? C#? It sure ain't anything from standard C++.
Methinks you're in the wrong newsgroup!

That my friend is programming in .NET in the wrong way. You know bad
programming. There are many out there that do these kind of things.
Especially consider that System::String,(which contains wchar_t
characters, provides a method ToCharArray() that converts the String to
a wchar_t array.

Now try to figure out what the above thing of casts will result to, and
how guaranteed is that, that thing will work.


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #7

P: n/a
Ioannis Vranos wrote:

That my friend is programming in .NET in the wrong way. You know, bad
programming. There are many out there that do these kind of things.

I placed a comma in the above to make its meaning more obvious.


--
Ioannis Vranos

http://www23.brinkster.com/noicys
Jul 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.