473,692 Members | 2,151 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 117992
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(firstNam e, 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.goo glegroups.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::Intero pServices::Mars hal::StringToHG lobalAnsi(lName ).ToPointer();

Jul 23 '05 #5

<Al************ @gmail.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
Thank you. I was able to fix the problem. Here is what I did:
String* lName = LastNameTexBox->Text;
char* pString =
(char*)System:: Runtime::Intero pServices::Mars hal::StringToHG lobalAnsi(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::Inte ropServices::Ma rshal::StringTo HGlobalAnsi(lNa me).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
13917
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 something like: char chars = "Hello!"; byte bytes = (byte) chars;
4
5424
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 typedef struct Rec { unsigned char msg; unsigned long len;
4
412
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
7019
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
5390
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 "System.Text.Encoding.ASCII.GetString(bytearray)" of .Net library, we found that the char (delimiters) specified above are replaced with different char.
18
7952
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 the string directly, I convert the string to a char using .ToCharArray() and set the first letter of each word to uppercase. The problem then is I can't figure out how to convert the char array back to a string. Whether I use .ToString() from the...
2
19393
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 array remain in the string and it's not terminated properly. Is there a nice way to trim these off (string.trim doesnt work) rather than my very nasty code below
3
2173
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 returns the index of the code in */ /* the LIBRARY structure if it is found. */ int findcode( LIBRARY *b, int n, char *tcode ) { int i;
0
2029
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 Studio 2005). The problem occurred when I trying to opening and reading file: ============= C++ ============= void LoadSourceFile(char * fileName, unsigned char * data, int length)
1
3812
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 = strToChars(texts); String^ shiftcs = domainUpDown1->Text; char *shiftc = strToChars(shiftcs); int shift = atoi(shiftc); char *cipher = encCCipher(text, shift); String^ ciphers = gcnew String(cipher); textBox2->Text = ciphers;
0
8600
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8535
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8796
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development projectóplanning, coding, testing, and deploymentówithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6458
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Duprť who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4555
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2968
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2234
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1955
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.