How to resolve the algorithm Letter frequency step by step in the Action! programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Letter frequency step by step in the Action! programming language

Table of Contents

Problem Statement

Open a text file and count the occurrences of each letter. Some of these programs count all characters (including punctuation), but some only count letters A to Z.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Letter frequency step by step in the Action! programming language

Source code in the action! programming language

INCLUDE "D2:PRINTF.ACT" ;from the Action! Tool Kit

CARD ARRAY histogram(256)

PROC Clear()
  INT i

  FOR i=0 TO 255
  DO histogram(i)=0 OD
RETURN

PROC ProcessLine(CHAR ARRAY line)
  INT i

  FOR i=1 TO line(0)
  DO
    histogram(line(i))==+1
  OD
RETURN

PROC ProcessFile(CHAR ARRAY fname)
  CHAR ARRAY line(255)
  BYTE dev=[1]

  Close(dev)
  Open(dev,fname,4)
  WHILE Eof(dev)=0
  DO
    InputSD(dev,line)
    ProcessLine(line)
  OD
  Close(dev)
RETURN

PROC PrintResult()
  INT i
  CHAR ARRAY s(10)

  FOR i=0 TO 255
  DO
    IF histogram(i) THEN
      StrC(histogram(i),s)
      PrintF(" %C:%-5S",i,s)
    FI
  OD
RETURN

PROC Main()
  CHAR ARRAY fname="H6:LETTE_KJ.ACT"
  BYTE LMARGIN=$52,old

  old=LMARGIN
  LMARGIN=0 ;remove left margin on the screen

  Put(125) PutE() ;clear the screen
  PrintF("Reading ""%S""...%E%E",fname)
  ProcessFile(fname)
  PrintResult()

  LMARGIN=old ;restore left margin on the screen
RETURN

  

You may also check:How to resolve the algorithm Sub-unit squares step by step in the XPL0 programming language
You may also check:How to resolve the algorithm Attractive numbers step by step in the 8080 Assembly programming language
You may also check:How to resolve the algorithm Run-length encoding step by step in the Action! programming language
You may also check:How to resolve the algorithm Problem of Apollonius step by step in the REXX programming language
You may also check:How to resolve the algorithm Infinity step by step in the MiniScript programming language