Welcome! Log In Create A New Profile

Advanced

BV508 & SD card how to read file by line ?

Posted by ls7u 
BV508 & SD card how to read file by line ?
August 06, 2015 12:34PM
HI this may be a simple answer but i can't seem to work out how to read a single line or loop through line by line of a txt file.

The code below just prints the whole contents of the file.


dim f, s$[128] ,count
f = fopen("CONF.txt","r")


fread(s$,40,*count,f)
print s$ // 



fclose(f)

Thanks
Luke
Re: BV508 & SD card how to read file by line ?
August 06, 2015 05:02PM
You can check for line end "\n" or carriage return "\r" or you can use fgets which gets 1 line:

function x(line)
dim f, a$[128], j
    f=fopen("start.bas","r")
    if f <> 0 then
        for j = 0 to line
            fgets(a$,f)
        next
        print a$
    endif
end
function x will return the line number requested, there is no error checking for end of file to make things simple in this example.
Check the keywords listing: http://www.bypic.co.uk/index.php/Key_Words
Re: BV508 & SD card how to read file by line ?
August 10, 2015 08:46PM
Jim , That works for me !

Thanks for your help

Luke
Re: BV508 & SD card how to read file by line ?
September 11, 2015 03:39PM
jim,

Is there a method for stripping the cr and line feeds off the end of a readline ?

cheers

Luke
Re: BV508 & SD card how to read file by line ?
September 12, 2015 09:16AM
something like
newLine$ = mid$(line$,0,strlen(line$)-2)
not tested, just a thought
Sorry, only registered users may post in this forum.

Click here to login