Menu

Can't insert Line Feed [CHR$(10)] from GW-Basic program to an output ASCII file

Anonymous
2016-03-20
2016-03-25
  • Anonymous

    Anonymous - 2016-03-20

    Well, "basically," it doesn't seem to work, though I've tried every variation I can think of (easily 20+, mainly variations of PRINT #1 and WRITE #1 from the GW-Basic program).

    The output to the file is one to three integers in a four space field. This works fine in the output file, but it all comes out in one continuous line rather than breaking into separate lines where the line feed character was supposed to go.

    By the way, the program works fine when the output is on the screen: the lines break where they are programmed to do so. I'm not sure whether the program sends CHR$(10) to the output file or not. FIND does not recognize it there, but it does not recognize some of the integers either, so it is perhaps inappropriate for this purpose.

    Thank you for your consideration...and, I hope, help.

    Richard

     
    • Rob Hagemans

      Rob Hagemans - 2016-03-20

      Hi Richard, happy to help. Could you clarify what the problem is? I'm afraid I don't understand from your message what it is that doesn't work. Would you be able to send me the GW-BASIC program you're trying to run, which isn't working correctly?

       
      • Rob Hagemans

        Rob Hagemans - 2016-03-25

        Hi Richard, I had another look at this. This:

        open "output.txt" for output as 1
        print#1, 12;chr$(10);32767;chr$(10);45;chr$(10)
        close
        

        works without problems for me; the output is three integers delimited by LF characters.

         12
         32767
         45
        

        What program do you use to view the output? Notepad on Windows, for example, will not show LFs correctly: you'll get everything on one line. Wordpad or most other text editors will do fine. The best way to check is to use a hex editor; the above output.txt looks for me like this:

        0000000: 2031 3220 0a20 3332 3736 3720 0a20 3435
        0000010: 200a 0d0a 1a
        

        where the LFs are shown as character 0a. This is identical to the output of GW-BASIC for the same commands.

        If you want a line break that works with Notepad, use CRLF, like this:

        open "output.txt" for output as 1
        print#1, 12;chr$(13);chr$(10);32767;chr$(13);chr$(10);45
        close
        

        or simply use separate PRINT statements for each number.

        Hope this helps,
        Rob

         
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.