473,385 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 117976
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.