Writing to file

 
Hi friends,
int filehandle0l=FileOpen(File_Name1,FILE_TXT|FILE_WRITE|FILE_READ|FILE_SHARE_READ); 
                  if(filehandle0l!=INVALID_HANDLE) 
                  { 
                    FileSeek(filehandle0l,0,SEEK_END);
                    FileWrite(filehandle0l,"a");
                    FileClose(filehandle0l); 
                  } 
the above code give me the result as follows
a
a
a
a
a
a
a
a
a
a
But I need the result as follows
aaaaaaaaaaaaaaaaaaaa
Please help me...thanks.
 
string text = "aaaaaaaaaaaaaaaaaaaa";

int filehandle0l=FileOpen(File_Name1,FILE_TXT|FILE_WRITE|FILE_READ|FILE_SHARE_READ); 
                  if(filehandle0l!=INVALID_HANDLE) 
                  { 
                    FileSeek(filehandle0l,0,SEEK_END);
                    FileWrite(filehandle0l,text,StringLen(text));
                    FileClose(filehandle0l); 
                  } 
 
I cannot already define string text like you defined. It is generated by some conditions.
 
Clement Chand C S:
I cannot already define string text like you defined. It is generated by some conditions.
Then open the file with FILE_BIN and use FileWriteInteger with CHAR_VALUE flag.
 
Clement Chand C S:
Hi friends, the above code give me the result as follows But I need the result as follows Please help me...thanks.

Build your string before writing to the file then?

// build string however you do it
for(int i=0;i<5;i++)
  tx+="a";

 int filehandle0l=FileOpen(filename,FILE_TXT|FILE_WRITE|FILE_READ); 
 FileSeek(filehandle0l,0,SEEK_END);
 FileWrite(filehandle0l,tx);
 FileClose(filehandle0l); 
 
Mohammad Hossein Sadeghi:
Then open the file with FILE_BIN and use FileWriteInteger with CHAR_VALUE flag.

hi do you mean as follows?

if(condition)
                 {
                
                  int filehandle0l=FileOpen("File_Name1.bin",FILE_BIN|FILE_WRITE|FILE_READ|FILE_SHARE_READ); 
                  if(filehandle0l!=INVALID_HANDLE) 
                  { 
                    FileSeek(filehandle0l,0,SEEK_END);
                    FileWriteInteger(filehandle0l,"a",CHAR_VALUE);
                    FileClose(filehandle0l); 
                    
                    
                  } 

if so i am getting the result as result

 
andrew:

Build your string before writing to the file then?

Please have a look at
for()

{


if(condition)
                 {
                
                  int filehandle0l=FileOpen(File_Name1,FILE_TXT|FILE_WRITE|FILE_READ|FILE_SHARE_READ); 
                  if(filehandle0l!=INVALID_HANDLE) 
                  { 
                    FileSeek(filehandle0l,0,SEEK_END);
                    FileWrite(filehandle0l,"l");
                    FileClose(filehandle0l); 
                    
                    
                  } 
                                
                  
                  
                  }
      
   ///////////////////////////////////
   if(condition)
                 {
                  int filehandle0l=FileOpen(File_Name1,FILE_TXT|FILE_WRITE|FILE_READ|FILE_SHARE_READ); 
                  if(filehandle0l!=INVALID_HANDLE) 
                  { 
                    FileSeek(filehandle0l,0,SEEK_END);
                    FileWrite(filehandle0l,"r");
                    FileClose(filehandle0l); 
                  } 
                  
                            
                  }
  ///////////////////////////////////////////////
  if(condition)
                 {
                  int filehandle0l=FileOpen(File_Name1,FILE_TXT|FILE_WRITE|FILE_READ|FILE_SHARE_READ); 
                  if(filehandle0l!=INVALID_HANDLE) 
                  { 
                    FileSeek(filehandle0l,0,SEEK_END);
                    FileWrite(filehandle0l,"b");
                    FileClose(filehandle0l); 
                  }
                            
                  } 
  ////////////////////////////////////
  if(condition)
                 {
                  int filehandle0l=FileOpen(File_Name1,FILE_TXT|FILE_WRITE|FILE_READ|FILE_SHARE_READ); 
                  if(filehandle0l!=INVALID_HANDLE) 
                  { 
                    FileSeek(filehandle0l,0,SEEK_END);
                    FileWrite(filehandle0l,"k");
                    FileClose(filehandle0l); 
                  }
                            
                  } 

}
depending on conditions this may give the result as
r
l
k
b
k
k
r
l
but i need the result as
rlkbkkrl
Pls help. thank you.
 

It's because a new line character \n will be automatically added.

FileWrite

The function is intended for writing of data into a CSV file, delimiter being inserted automatically unless it is equal to 0. 

After writing into the file, the line end character "\r\n" will be added.

In your case that is undesirably because it will put every new entry on a new line.

In stead you want to write a function that appends your data to the same line until you manually add a \n new line chr.

 
Clement Chand C S:

hi do you mean as follows?

if so i am getting the result as

if(condition)
  {
   int filehandle0l=FileOpen("File_Name1.bin",FILE_BIN|FILE_WRITE|FILE_READ|FILE_SHARE_READ); 
   if(filehandle0l!=INVALID_HANDLE) 
   { 
     FileSeek(filehandle0l,0,SEEK_END);
     FileWriteInteger(filehandle0l,'a',CHAR_VALUE);
     FileClose(filehandle0l); 
   }

Please mind double quotes around the letter (a) are changed to single quote. "a" -> 'a'

 
Mohammad Hossein Sadeghi:

Please mind double quotes around the letter (a) are changed to single quote. "a" -> 'a'

ohh! sorry friend, my mistake. Yes now it works!!. thank you so much.

Thanks to all.....

 
Clement Chand C S:

ohh! sorry friend, my mistake. Yes now it works!!. thank you so much.

Thanks to all.....

Happy to hear it helped.

You're welcome.

Reason: