LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

How to write from a buffer to a file

Hello everyone,
                    I have posted the same problem earlier and received satisfactory replies.But for my application it was appropriate only to some extent.My problem is that I have read a file using OpenFile() and Read a line using ReadLine().I used ReadLine since I have to do operations on each line of the file.Now each line of my file(abc.txt) contains certain informations.For example name,address,employeeid,father'sname,salary etcabout 25 such items.Now I require only certain portions of the line.i.e.,name,salary and employeeid(about 19 items).And these informations are to be copied onto another file. 
So I took each line ,scanned for a comma (since I know the position of each field it was easy by calling an explicitely defined function).
And now i declared variables scname,scsalary,scemployeeid and during each pass of the function(scanning for comma) corresponding values are stored in these variables eg name in scname.Now wtihin in this loop i must write the values of scname,scsalary and scemployeeid to another file.Again I will take the next line and do the same steps and will write to the file..Now I am able to scan for comma but don't know how to write to another file.Since I have used ReaLine() I have only an integer handle.So I can't use fprintf.Is there any function that I can use with ReadLine.I want To write as scname,(comma is to be placed)scemployeeid,scsalary.How could I establish this?
eg:abc.txt contains
     Name  ,address,father'sname,salary,employeeid etc(abt 25 such items)
    Edwin,12street,sam,50000,ss123.
and copied file must contain
   Name,salary,employeeid(abt 19 items)
            Edwin,50000,ss123.
                           Expecting help from u all,
                                                                                                      Vava                                           
 
 
 
0 Kudos
Message 1 of 3
(3,167 Views)

You simply need to open a new file and write to it using WriteLine.

If you are readind and writing in the same process, your loop will be the following:

OpenFile (source, open for reading in ascii mode)

OpenFile (destination, open for writing in ascii mode)

while (1) {

   result = ReadLine (from source)

   if (result == -2) break         // End-of-file reached

   Scan the buffer

   Create the new buffer with selected fields using sprintf or Fmt functions

    WriteLine (to destination)

}

CloseFile (source)

CloseFile (destination)



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 2 of 3
(3,159 Views)

Hello Roberto,

                     Thanks a lot for ur advice.Now I am able to copy the whole file,do the scanning and write it to other file.Earlier I was not getting last two lines of the file.Now the problem has gone.Anyway once again thanking u.Expecting the same cooperation from u in future.

                                                                                                                        Vava

                                                                                                                                         

0 Kudos
Message 3 of 3
(3,134 Views)