472,373 Members | 1,481 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,373 software developers and data experts.

Converting String to Char Array

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
7 117891
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
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

<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
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

<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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: matt melton | last post by:
Hi there, I am trying to write a method that accepts an array of any primitive type and will return the same array without copying memory as an array of bytes. ie. I'd like to be able to do...
4
by: jagmeena | last post by:
Hello, I am sure this problem has been addressed before, however, I could'nt get a suitable solution to my problem. Hence I am posting here. Thanks a lot for all your help. The code I have is ...
4
by: x | last post by:
converting 1944 to '1','9','4','4' how can I convert a number such as 1944 to a character array? thanks!
6
by: karthik.naig | last post by:
Hi, This was the routine I wrote earlier to convert a C++ string to a char array. But I found that the char* array consisted only of junk after returning from the below function.
4
by: Prabhu | last post by:
Hi, We are having problem in converting a byte array to string, The byte array has char(174), char(175), char(240), char(242) and char(247) as delimiters for the message. when we use...
18
by: Marcio Kleemann | last post by:
I need to force the first letter of each word in a line of text to uppercase. The text comes from a TextBox control in a Web Form. I'm new to ..NET and am having a problem. Since I can't modify...
2
by: claire | last post by:
I have a char that i convert to a string as follows m_tHeader.m_sshortname is defined as char; string result = new string(m_tHeader.m_sshortname); The problem is that any '\0' chars in the...
3
by: fakeprogress | last post by:
How would I go about converting this C code to C++? /* LIBRARY is an array of structures */ /* This function compares 'tcode' with */ /* existing codes in the array. */ /* It...
0
by: anide | last post by:
Hi all Iíve some problem, Iím trying to converting a sorting algorithm from C++ to C#. In C++ Iíve compiled it using MSVC and its working properly, and in C# Iím using .NET Framework 2.0 (Visual...
1
by: vcbytes | last post by:
I am having a problem with the following code: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) { String^ texts = textBox1->Text; char *text =...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
2
by: Ricardo de Mila | last post by:
Dear people, good afternoon... I have a form in msAccess with lots of controls and a specific routine must be triggered if the mouse_down event happens in any control. Than I need to discover what...
1
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
0
DizelArs
by: DizelArs | last post by:
Hi all) Faced with a problem, element.click() event doesn't work in Safari browser. Tried various tricks like emulating touch event through a function: let clickEvent = new Event('click', {...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.