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

LPTSTR to char *.. How

P: n/a
Hi ,
is this correct to have final LPTSTR to char *

CString fname(argv [1]);
LPTSTR p1 = fname.GetBuffer(fname.GetLength());
char teststr[1000];
sprintf(teststr,"%s",p1); //or
strcpy(teststr,p1);

is this code to have my null terminated teststr.
Thanks
free2cric
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a

free2cric wrote:
Hi ,
is this correct to have final LPTSTR to char *

CString fname(argv [1]);
LPTSTR p1 = fname.GetBuffer(fname.GetLength());
char teststr[1000];
sprintf(teststr,"%s",p1); //or
strcpy(teststr,p1);

is this code to have my null terminated teststr.
Thanks
free2cric


Much better is to use std::string class and c_str() method.

Jul 23 '05 #2

P: n/a
free2cric wrote:
Hi ,
is this correct to have final LPTSTR to char *

CString fname(argv [1]);
LPTSTR p1 = fname.GetBuffer(fname.GetLength());
char teststr[1000];
sprintf(teststr,"%s",p1); //or
strcpy(teststr,p1);

is this code to have my null terminated teststr.
Thanks
free2cric


LPTSTR and CString are Microsoft specific types,
and best discussed in a Microsoft newsgroup.
Read the FAQs and welcome.txt below for newsgroup
suggestions.

A more portable type is std::string from the
STL.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library

Jul 23 '05 #3

P: n/a
I agree with the others regarding string. However, if you are stuck on
CString's, you can do

CString fname(argv[1]);
char teststr[1000];
strcpy( teststr, (LPCTSTR) fname );
"free2cric" <fr*******@yahoo.com> wrote in message
news:e8**************************@posting.google.c om...
Hi ,
is this correct to have final LPTSTR to char *

CString fname(argv [1]);
LPTSTR p1 = fname.GetBuffer(fname.GetLength());
char teststr[1000];
sprintf(teststr,"%s",p1); //or
strcpy(teststr,p1);

is this code to have my null terminated teststr.
Thanks
free2cric

Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.