Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

converting type "char" to type "string"

Status
Not open for further replies.

mzufferey

Programmer
Aug 30, 2001
4
CH
Hi all,

I have a little problem using string and array of char.

I have a:

CString lit[10];
char mots[500];

Then I open a first file (txt), and get char per char until the program found a separator (like < and >) and it store the result in mots. If mots it is the good one, I copy the result in lit[j]; I search for 7 right word. After that I close the file, change the name, and open the next file the retrive the information I need. After opne a new file, I initialize the variables.
This work good with C++ with DEBUG configuration, but if I set to RELEASE configuration, it work a first time (for the first file) and the I have I proble of writing memory at the point

lit[j]=mots;

Have you a solution for this problem or an Idea or other ?

mots must be an array of char, because I use fgetc function and store the read charachter into mots, beginnig at index 0. A word find I initialize mots, before taking the follow word.

Many thank to all.

Best regards.
 
use CSrtingArray instead of CString Ion Filipski
1c.bmp


filipski@excite.com
 
Thanks !

But I still need a CString, if I do no want to remake my program. I use my CString in if to compare the lit content to a const Cstring.

I think the problem is in mots and not lit[j];

I do not know how it work Release, but with Debug all work.
I think is a memory problem.

I just need to do:

lit[j]=mots; As many time I want and not only one time.

Best regards.
 
the problem is what operator[] indicate the index of character number i in the string.
If CString x = &quot;0123456789&quot;
x[1] for example will return '1'
so there is no choice. Ion Filipski
1c.bmp


filipski@excite.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top