LPTSTR to char *.. How

F

free2cric

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
 
S

SnaiL

free2cric said:
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.
 
T

Thomas Matthews

free2cric said:
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
 
W

Winbatch

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,159
Messages
2,570,881
Members
47,418
Latest member
NoellaXku

Latest Threads

Top