 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Cenk Guest
|
Posted: Thu Feb 23, 2006 4:03 pm Post subject: write string to file |
|
|
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
|
Posted: Thu Feb 23, 2006 4:03 pm Post subject: Re: write string to file |
|
|
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
|
Posted: Thu Feb 23, 2006 4:03 pm Post subject: Re: write string to file |
|
|
"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
|
Posted: Thu Feb 23, 2006 4:03 pm Post subject: Re: write string to file |
|
|
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
|
Posted: Thu Feb 23, 2006 4:03 pm Post subject: Re: write string to file |
|
|
| 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
|
Posted: Thu Feb 23, 2006 5:03 pm Post subject: Re: write string to file |
|
|
| how to write them line by line? |
|
| Back to top |
|
 |
Cenk Guest
|
Posted: Thu Feb 23, 2006 5:03 pm Post subject: Re: write string to file |
|
|
thanks folks
god bless |
|
| Back to top |
|
 |
Vladimir Stefanovic Guest
|
Posted: Thu Feb 23, 2006 8:03 pm Post subject: Re: write string to file |
|
|
| 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
|
Posted: Thu Feb 23, 2006 8:03 pm Post subject: Re: write string to file |
|
|
"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
|
Posted: Thu Feb 23, 2006 10:03 pm Post subject: Re: write string to file |
|
|
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
|
Posted: Fri Feb 24, 2006 5:03 am Post subject: Re: write string to file |
|
|
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
|
Posted: Fri Feb 24, 2006 5:03 am Post subject: Re: write string to file |
|
|
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 |
|
 |
|
|
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
|
|