22 lines
515 B
Text
22 lines
515 B
Text
#APPTYPE CONSOLE
|
|
|
|
'Open a text file and count the occurrences of each letter.
|
|
FUNCTION countBytes(fileName AS STRING)
|
|
DIM c AS STRING
|
|
DIM ascii[]
|
|
DIM handle AS INTEGER = FILEOPEN(fileName, BINARY)
|
|
WHILE NOT FILEEOF(handle)
|
|
c = FILEGETC(handle)
|
|
IF c = "" THEN EXIT WHILE
|
|
ascii[ASC] = ascii[ASC(c)] + 1
|
|
WEND
|
|
FILECLOSE(handle)
|
|
RETURN ascii
|
|
END SUB
|
|
|
|
DIM counters = countBytes(COMMAND(1))
|
|
FOR DIM i = LBOUND(counters) TO UBOUND(counters)
|
|
PRINT i, TAB, IIF(i <= 32, i, CHR(i)), TAB, counters[i]
|
|
NEXT
|
|
|
|
PAUSE
|