BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

write string to file

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++)
View previous topic :: View next topic  
Author Message
Cenk
Guest





PostPosted: Thu Feb 23, 2006 4:03 pm    Post subject: write string to file Reply with quote



hi,
i wanna get the string from listbox then write it to a file but gives error!

FILE * pFile;
String str = ListBox1->Items->Strings[0];
pFile = fopen ("indicator.txt","wt+");
fputs(str,pFile);

fclose (pFile);
Back to top
Liz Albin
Guest





PostPosted: Thu Feb 23, 2006 4:03 pm    Post subject: Re: write string to file Reply with quote



On Thu, 23 Feb 2006 17:05:21 +0200, Cenk wrote:

Quote:
hi,
i wanna get the string from listbox then write it to a file but gives error!

FILE * pFile;
String str = ListBox1->Items->Strings[0];
pFile = fopen ("indicator.txt","wt+");
fputs(str,pFile);

fclose (pFile);

fputs() takes a char *, try str.c_str().

Or, of course, try using Strings::SaveToFile and writing the whole
thing at once.


--
liz
Back to top
Alan Bellingham
Guest





PostPosted: Thu Feb 23, 2006 4:03 pm    Post subject: Re: write string to file Reply with quote



"Cenk" <cenk1536 (AT) yahoo (DOT) com> wrote:

Quote:
hi,
i wanna get the string from listbox then write it to a file but gives error!

FILE * pFile;
String str = ListBox1->Items->Strings[0];
pFile = fopen ("indicator.txt","wt+");
fputs(str,pFile);

fclose (pFile);

Ah, yes.

It so happens that "indicator.txt" is an illegal filename under the 8.3
MS-DOS file naming system.

Oh, that's not what you think the error may be? Well, how are we to know
- you've not described any symptoms at all? You've not said which line
indicates the error.

In future, rather than just saying "but gives error", tell us WHAT THE
ERROR ACTUALLY IS!

Otherwise, it's so much harder to help.

Alan Bellingham
--
ACCU Conference 2006 - 19-22 April, Randolph Hotel, Oxford, UK
Back to top
Vladimir Stefanovic
Guest





PostPosted: Thu Feb 23, 2006 4:03 pm    Post subject: Re: write string to file Reply with quote

This line:

fputs(str,pFile);

Replace with this:

fputs(str.c_str(),pFile);

Quote:
i wanna get the string from listbox then write it to a file but gives
error!

Always provide us the error message you got



--
Best Regards,
Vladimir Stefanovic
Back to top
Cenk
Guest





PostPosted: Thu Feb 23, 2006 4:03 pm    Post subject: Re: write string to file Reply with quote

Quote:
FILE * pFile;
String str = ListBox1->Items->Strings[0];
pFile = fopen ("indicator.txt","wt+");
fputs(str,pFile);

fclose (pFile);

Could not find a match for fputs (AnsiString,FILE *)

Call to undefined function fputs
Back to top
Cenk
Guest





PostPosted: Thu Feb 23, 2006 5:03 pm    Post subject: Re: write string to file Reply with quote

how to write them line by line?
Back to top
Cenk
Guest





PostPosted: Thu Feb 23, 2006 5:03 pm    Post subject: Re: write string to file Reply with quote

thanks folks
god bless
Back to top
Vladimir Stefanovic
Guest





PostPosted: Thu Feb 23, 2006 8:03 pm    Post subject: Re: write string to file Reply with quote

Quote:
how to write them line by line?

ListBox1->Items->SaveToFile( ExtractFilePath( ParamStr( 0 ) ) +
"somefile.txt" );



--
Best Regards,
Vladimir Stefanovic
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Thu Feb 23, 2006 8:03 pm    Post subject: Re: write string to file Reply with quote

"Cenk" <cenk1536 (AT) yahoo (DOT) com> wrote in message
news:43fdd696$1 (AT) newsgroups (DOT) borland.com...

Quote:
Could not find a match for fputs (AnsiString,FILE *)

You need to use the AnsiString's c_str() method to get a pointer to the raw
character data:

String str = ListBox1->Items->Strings[0];
FILE *pFile= fopen("indicator.txt", "wt+");
if( pFile )
{
fputs(str.c_str(), pFile); // <-- here
fclose(pFile);
}


Gambit
Back to top
Cenk
Guest





PostPosted: Thu Feb 23, 2006 10:03 pm    Post subject: Re: write string to file Reply with quote

how to read from the file i just wrote into?
FILE * pFile;
FILE * rFile;
int index,i,pos;
String str_w,str_r;
index = ListBox1->Items->Count;
index = index -1;
pFile = fopen ("cenkom.txt","w+t");
for (i = 1;i<= index ;i++)
{
str_w = ListBox1->Items->Strings[i];
pos = str_w.Pos(' ');
str_w = str_w.SubString(pos+1,7);
str_w = str_w +"\n";
fputs(str_w.c_str(),pFile);
}


//rFile = fopen ("cenk.txt" , "r");
if (pFile == NULL)
perror ("Error opening file");
else
{

while (!feof(pFile))
{

ShowMessage (fgets (str_r.c_str() , 255 , pFile));
}

}
//fclose (rFile);
fclose (pFile);
Back to top
Liz Albin
Guest





PostPosted: Fri Feb 24, 2006 5:03 am    Post subject: Re: write string to file Reply with quote

On Thu, 23 Feb 2006 18:16:59 +0200, Cenk wrote:

Quote:
how to write them line by line?

Iterate through the array, write each line.

But, I repeat, using SaveToFile would be more sensible
--
liz
Back to top
Liz Albin
Guest





PostPosted: Fri Feb 24, 2006 5:03 am    Post subject: Re: write string to file Reply with quote

On Thu, 23 Feb 2006 22:42:06 +0200, Cenk wrote:

Quote:
how to read from the file i just wrote into?

Use LoadFromFile()
--
liz
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Language C++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.