w1k Posted February 2, 2011 Share Posted February 2, 2011 (edited) hi, i loading texts from external txt files.. how i can separate words at end of line? now is pretty ugly. source of viewing txt files (tbasic) Edited February 2, 2011 by w1k Quote Link to comment Share on other sites More sharing options...
Rybags Posted February 2, 2011 Share Posted February 2, 2011 A bit of fancy programming... check for word overflow - if last character of a line and first chr of the next line is alpha, then you'd want to truncate the line backwards from there so the last character printed is a SPACE or punctuation mark. You could probably do it by just making a few pointer variables into the string. Use loops to do the character scanning. Or does Turbo-Basic have some sort of INSTR() function. Quote Link to comment Share on other sites More sharing options...
w1k Posted February 2, 2011 Author Share Posted February 2, 2011 A bit of fancy programming... check for word overflow - if last character of a line and first chr of the next line is alpha, then you'd want to truncate the line backwards from there so the last character printed is a SPACE or punctuation mark. You could probably do it by just making a few pointer variables into the string. Use loops to do the character scanning. Or does Turbo-Basic have some sort of INSTR() function. some little hint or example? im poor programmer Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted February 2, 2011 Share Posted February 2, 2011 (edited) I dunno what "tBasic" is, but you'd just fetch each character out of the file and build a temp string (WORD$) until the space character is encountered. Then, check the current column plus the length of the word against the maximum columns (40). If > 0, print the word on the current line (or else, print a carriage return). I'm too lazy to look up the correct PEEK location for line 333, but I think that it would go something like this: 330 TRAP 340 331 GET #2,A 332 IF A <> 32 THEN WORD$(LEN(WORD$)+1)=CHR$(A):GOTO 331 333 IF 40-PEEK(91)+LEN(WORD$)>0 THEN 335 334 ?#3:GOTO 336:REM end current line 335 ?#3;CHR$(32);:REM continue current line 336 ?#3;WORD$;:WORD$="":REM print the word and clear WORD$ 337 GOTO 331 Edited February 2, 2011 by Nukey Shay Quote Link to comment Share on other sites More sharing options...
Synthpopalooza Posted February 2, 2011 Share Posted February 2, 2011 TurboBASIC does have an instr function, works like this: A=INSTR("This is a sentence."," ") will return the first location of the space character " " in the first string. In this example, the variable A will be set equal to 5 (where the first space character is). Quote Link to comment Share on other sites More sharing options...
w1k Posted February 2, 2011 Author Share Posted February 2, 2011 thats code doesnt work Quote Link to comment Share on other sites More sharing options...
Nukey Shay Posted February 2, 2011 Share Posted February 2, 2011 I said the PEEK location might be incorrect This test program worked fine in regular Atari Basic. It's basically the same as the above, but with line 333 altered a bit. 10 DIM WORD$(255) 20 POKE 752,1 30 POKE 82,0 40 OPEN #2,4,0,"D:TEXTFILE" 330 TRAP 340 331 GET #2,A 332 IF A<>32 THEN WORD$(LEN(WORD$)+1)=CHR$(A):GOTO331 333 IF 39-(PEEK(99)+LEN(WORD$))>0 THEN 335 334 ?:GOTO336 335 ?" "; 336 ?WORD$;:WORD$="" 337 GOTO 331 340 CLOSE #2 Quote Link to comment Share on other sites More sharing options...
w1k Posted February 3, 2011 Author Share Posted February 3, 2011 can you add this code into my source? Quote Link to comment Share on other sites More sharing options...
Roydea6 Posted February 3, 2011 Share Posted February 3, 2011 It seems that it would be easier to pre-format the original text to have a [return] at the space before the line wraps at column 39. Quote Link to comment Share on other sites More sharing options...
w1k Posted February 3, 2011 Author Share Posted February 3, 2011 ok, i try it Quote Link to comment Share on other sites More sharing options...
Roydea6 Posted February 5, 2011 Share Posted February 5, 2011 This effort might be a little easier but similar to the code you are using..and will stop when screen fills to 22 lines. 10 REM ALL TEXT MUST BE ENDED WITH THE RETURN KEY ON EACH <40 CHARACTER LINE. 100 DIM A$(44):GRAPHICS 0:POKE 82,0:? "}" 110 ? ,"A=READ - FIRST.TXT" 120 ? ,"B=READ - SECOND.TXT" 130 ? ,"C=READ - THIRD.TXT" 140 POKE 764,255:IF PEEK(764)=255:GOTO 140:ENDIF 145 ? "}":REM CLEAR SCREEN 150 IF PEEK(764)=63:A$="D:FIRST.TXT":ENDIF 160 IF PEEK(764)=21:A$="D:SECOND.TXT":ENDIF 170 IF PEEK(764)=18:A$="D:THIRD.TXT":ENDIF 200 TRAP 250:OPEN #1,4,0,A$ 210 INPUT #1,A$ A$:IF PEEK(84)<22:GOTO 210:ENDIF 220 POKE 764,255:? "PRESS KEY FOR MORE" 230 IF PEEK(764)=255 THEN 230 240 POKE 764,255:? "}":GOTO 210 250 CLOSE #1:POKE 764,255:CLR :POKE 82,2:END Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.