473,441 Members | 1,826 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,441 software developers and data experts.

convert char * to char []

Help!

I am trying to figure this out, and I have the impression that it
should be really easy, but I'm at a loss.

Here's my problem:

I want to take the output from

const char * string::c_str();

and convert it in some appropriate fasion so that I can use it as the
input to this function:

void Config(const char filename[]);

any help is greatly appreciated!

trevis

Aug 23 '07 #1
5 3132
T. Crane wrote:
I am trying to figure this out, and I have the impression that it
should be really easy, but I'm at a loss.

Here's my problem:

I want to take the output from

const char * string::c_str();

and convert it in some appropriate fasion so that I can use it as the
input to this function:

void Config(const char filename[]);
Just pass the call to your string's 'c_str' directly:

..blahblah...
Config(mysring.c_str());

The trick here is that the declaration of 'filename' argument is not
what it seems, and in fact 'filename' is just a pointer:

const char filename[] === const char *filename

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Aug 23 '07 #2
On Aug 23, 4:58 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
T. Crane wrote:
I am trying to figure this out, and I have the impression that it
should be really easy, but I'm at a loss.
Here's my problem:
I want to take the output from
const char * string::c_str();
and convert it in some appropriate fasion so that I can use it as the
input to this function:
void Config(const char filename[]);

Just pass the call to your string's 'c_str' directly:

..blahblah...
Config(mysring.c_str());

The trick here is that the declaration of 'filename' argument is not
what it seems, and in fact 'filename' is just a pointer:

const char filename[] === const char *filename

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask
Yeah, that's what I tried. For some reason it doesn't work. It
compiles fine, but something goes wrong after that, so I'm going to
have to debug it.

thanks,
trevis

Aug 23 '07 #3
Hi!

T. Crane schrieb:
Yeah, that's what I tried. For some reason it doesn't work. It
compiles fine, but something goes wrong after that, so I'm going to
have to debug it.
Note: the array becomes invalid when you change the string or when the
string goes out of scope (is destructed).

Frank
Aug 24 '07 #4
On Aug 23, 8:50 pm, Frank Birbacher <bloodymir.c...@gmx.netwrote:
Hi!

T. Crane schrieb:
Yeah, that's what I tried. For some reason it doesn't work. It
compiles fine, but something goes wrong after that, so I'm going to
have to debug it.

Note: the array becomes invalid when you change the string or when the
string goes out of scope (is destructed).

Frank
So it seems that my problem is definitely in the Config function. The
filename parameter that is passed to Config() ends up going to another
function called CreateFile. CreateFile's first parameter is of the
type LPCTSTR, and there is some issue in coverting my const char * to
the LPCTSTR type. Something to do with Unicode. I dunno. Any help
understanding this is appreciated.

thanks,
trevis

Aug 24 '07 #5

T. Crane <tr**********@gmail.comwrote in message...
>
So it seems that my problem is definitely in the Config function. The
filename parameter that is passed to Config() ends up going to another
function called CreateFile. CreateFile's first parameter is of the
type LPCTSTR, and there is some issue in coverting my const char * to
the LPCTSTR type. Something to do with Unicode. I dunno. Any help
understanding this is appreciated.
thanks, trevis
If it's a wide-char, try 'std::wstring'.

There's also the 'vector-trick':

std::vector<TCHARMyString( 1024 ); // be sure it's big enough
LPCTSTR pwString = &MyString.at(0);

Try some tests to find out what you are using:

char Ch( 'A' );
wchar_t wCh( 'A' );
LPCTSTR pS = &Ch;
LPCTSTR pwS = &wCh;

Which one does not compile? (comment-out one at a time)

TCHAR dummy('A');
std::cout<<"sizeof(dummy)="<<sizeof(dummy)<<std::e ndl;
std::cout<<"sizeof(TCHAR)="<<sizeof(TCHAR)<<std::e ndl;

What is the output of those lines?

If 'Config()' is something you wrote, post it.

--
Bob R
POVrookie
Aug 24 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Markus Hämmerli | last post by:
I ' ll tra to convert a Cstring to char* without success. I working in a Unicode enabled environment this is working in Unicode CString source = _T("TestString"); TCHAR *szSource =...
1
by: Sam Smith | last post by:
Hi, I wan't a function to take a const char*, a start bit position and number of bits and convert that bit-stream into a primitive of desired type. I.e. something like: char convert(const...
5
by: Brad Moore | last post by:
Hey all, I'm getting the following compiler error from my code. I was wondering if anyone could help me understand the concept behind it (I actually did try and compile this degenerate...
7
by: whatluo | last post by:
Hi, all I'm now working on a program which will convert dec number to hex and oct and bin respectively, I've checked the clc but with no luck, so can anybody give me a hit how to make this done...
7
by: MilanB | last post by:
Hello How to convert char to int? Thanks
15
by: Yifan | last post by:
Hi Does anybody know how to convert System::String* to char*? I searched the System::String class members and did not find any. Thanks Yifan
19
by: caramel | last post by:
i've been working on this program forever! now i'm stuck and going insane because i keep getting a syntax error msg and i just can't see what the compiler is signaling to! #include <stdio.h>...
3
by: Eric BOUXIROT | last post by:
hi, i must convert all of these eVC++ prototypes to use with VB.NET.... DLLEXPORT long F_BDO_MessageBoxOK(char *IN_title, char *IN_msg ); DLLEXPORT long F_BDO_MessageBoxOUINON(char *IN_title,...
12
by: GRoll35 | last post by:
I get 4 of those errors. in the same spot. I'll show my parent class, child class, and my driver. All that is suppose to happen is the user enters data and it uses parent/child class to display...
5
by: Zytan | last post by:
I am surprised that a single character string is not auto-created from a single char. It is hard to find information on converting a char into a string, since most people ask how to convert char...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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...
0
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,...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.