Solved

How to convert string to char[] in C++ 2008

Posted on 2009-04-06
5
1,260 Views
Last Modified: 2012-05-06
I have a array char c[256]

How to convert txtbox1->Text to c[]?

Thank you. The environment is c++2008
0
Comment
Question by:xuanspider
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 19

Expert Comment

by:alb66
ID: 24075272
char* pText = Marshal::StringToHGlobalAnsi( txtbox1->Text );
strcpy( c, pText );
Marshal::FreeHGlobal( pText );
0
 

Author Comment

by:xuanspider
ID: 24075404
IntPtr can not convert to char *, my environment is .net 2008
0
 
LVL 19

Accepted Solution

by:
alb66 earned 250 total points
ID: 24077619
I forgot two cast...

char* pText = (char*)Marshal::StringToHGlobalAnsi( txtbox1->Text );
strcpy( c, pText );
Marshal::FreeHGlobal( (IntPtr)pText );
0
 

Author Comment

by:xuanspider
ID: 24083087
I'm sorry that still cannot, same error. Please note that the environment is C# express 2008
0
 

Author Closing Comment

by:xuanspider
ID: 31566924
Anyhow, thanks.
0

Featured Post

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The following diagram presents a diamond class hierarchy: As depicted, diamond inheritance denotes when two classes (e.g., CDerived1 and CDerived2), separately extending a common base class (e.g., CBase), are sub classed simultaneously by a fourt…
In Easy String Encryption Using CryptoAPI in C++ (http://www.experts-exchange.com/viewArticle.jsp?aid=1193) I described how to encrypt text and recommended that the encrypted text be stored as a series of hexadecimal digits -- because cyphertext may…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question