Announcement

Collapse
No announcement yet.

extra line at the end of a file

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • extra line at the end of a file

    can anybody explain to me why I have a extra line at the end of my output file even thou that line doesn't exist in the input file i'm using v2.10f in windows 95
    part of code:
    open arg$(1) for binary as #1 len = 8096
    open arg$(2) for binary as #2
    do
    get$ #1,435,idx$
    idx1$ = left$(idx$,433)+chr$(13,10)
    if idx1$ = "" then exit loop
    put$ #2,idx1$
    loop until eof(1)
    close #1,#2
    end


  • #2
    Try this......

    open arg$(1) for binary as #1 len = 8096
    open arg$(2) for binary as #2
    'do
    do while not eof(1)
    get$ #1,435,idx$
    idx1$ = left$(idx$,433)+chr$(13,10)
    if idx1$ = "" then exit loop
    put$ #2,idx1$
    'loop until eof(1)
    loop
    close #1,#2
    end

    James Moneypenny

    ------------------


    [This message has been edited by James Moneypenny (edited February 11, 2000).]
    James Moneypenny
    mailto:[email protected][email protected]</A>

    Comment


    • #3
      There is a flaw here too:

      Code:
      idx1$ = left$(idx$,433)+chr$(13,10)
      if idx1$ = "" then exit loop
      The second line will NEVER be true because the preceding line will always add a CR+LF pair to IDX1$, therefore IDX1$ will be at least 2 bytes long at all times.

      Finally, because the input file is BINARY, it would be better to calculate the number of loops based on the length of the file and the "record" size, rather than relying on EOF()... this way the actual size of the input file does not have to be a multiple of the "record" size. ie FOR X% = 1 to LOF(1) \ 435

      Note: EOF() only returns TRUE for a BINARY file _after_ the GET$ takes place, so testing for EOF(1) at the end of the loop is the best strategy.

      ------------------
      Lance
      PowerBASIC Support
      mailto:[email protected][email protected]</A>
      Lance
      mailto:[email protected]

      Comment


      • #4
        Because EOF() is only true after an incomplete GET/GET$, you need to add that logic INSIDE your loop:
        [code]
        DO
        GET$ #H,,TheData
        IF NOT EOF(H) THEN
        build output and write it
        ELSE
        EXIT DO
        END IF
        LOOP

        MCM
        Michael Mattias
        Tal Systems Inc. (retired)
        Racine WI USA
        [email protected]
        http://www.talsystems.com

        Comment


        • #5
          I agree with Michael's logic on EOF issue.

          James Moneypenny


          ------------------


          [This message has been edited by James Moneypenny (edited February 11, 2000).]
          James Moneypenny
          mailto:[email protected][email protected]</A>

          Comment

          Working...
          X