Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

File pointer or pointer positioning

Status
Not open for further replies.

Volkmaniac

Technical User
Mar 19, 2003
104
US
Knob showed me a way I could count occurrences of an item within a text file:

fopen 1 fname read text
While not feof 1
fgets 01 sLine
If strncmp sLine "CCXXXX" 6
A++
else
If strncmp sLine "CCXXA" 5
B++
else
If strncmp sLine "CCXB" 4
C++
else

Now I'd like to take things a step further. Is there a way I can conduct the same type of search but only on specific columns within a file? For instance, let's say I have a file layout that tells me that a two digit code is in position 220-221 of each record in a file. Is there a way I can tell the script to only search those specific positions?
 
Bingo,

It finally worked. The tabs are counted as positions and they go up to 1540 in the file. I would have never got it to work if you didn't tell me about the 2 bytes for carriage return.

All that work for this output:

05
05
05
05
02
05
07
05

It's still not recognizing eof but I could probably specify the number of times the loop can run. This could be very useful for extracting information from files:

fopen 0 "S:\Client Services\FASTDATA\1001\rec\RFIIAR2I" read
fseek 0 235 0
While not feof 0
fread 0 sDpv 2 len
termmsg "%s" sDpv
Termwrites "`n`r"
If strnicmp sDpv "01" 2
A++
else
If strnicmp sDpv "02" 2
B++
else
If strnicmp sDpv "03" 2
C++
else
Endif
Endif
Endif
ftell 0 FilePos
statmsg "File position = %ld" FilePos
fseek 0 1542 1
Endwhile
fclose 0


Thanks yet again for all your help


 
Add this code after your fread command. It will check to see if the two-byte string is null. If so, then you are most likely at the end of the file:


if nullstr sDpv
exitwhile
endif

aspect@aspectscripting.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top