BEGIN [u]Search_Log(piratesLog)[/u]
Get query_type from user input
CASEWHERE query_type is
“name”: [u]searchName(piratesLog)[/u]
“role”: [u]searchRole(piratesLog)[/u]
ENDCASE
END [u]Search_Log[/u]
BEGIN [u]searchName(piratesLog)[/u]
Get target from user input
FOR i=1 TO piratesLog.length STEP 1
IF piratesLog[i].name == target THEN
PRINT piratesLog[i].name, piratesLog[i].role, piratesLog[i].age, piratesLog[i].mutiny
i = piratesLog.length + 1
ENDIF
ENDFOR
END searchName
BEGIN [u]searchRole(piratesLog)[/u]
Get target from user input
FOR i=1 TO piratesLog.length STEP 1
IF piratesLog[i].role == target THEN
PRINT piratesLog[i].name, piratesLog[i].role, piratesLog[i].age, piratesLog[i].mutiny
i = piratesLog.length + 1
ENDIF
ENDFOR
END [u]searchRole[/u]
Just a question with this problem - quite obviously, reading/writing to a sequential file both require a sentinel value of some sort. However, in the process of writing to a sequential file, you'll need to specify what this sentinel is to know when to stop writing. If, then, you go to read from the file like in the searching component of this program, you will end up with a previous sentinel value somewhere in your file as well as the ones added in the write you just did. Is it safe to assume that, prior reading the file for a search, that any previous sentinel values are removed?
BEGIN SpellSearcher
OPEN spells.txt for input
READ Spells from spells.txt
SET Count to 1
SET foundSpell to false
WHILE Spells(Count) <= length of spells.txt and foundSpell == false DO
GET input
IF input == Spells(Count) THEN
DISPLAY Spells(Count).Use
foundSpell = true
ELSE
DISPLAY “Entered spell does not exist!”
END IF
INCREMENT Count by 1
END WHILE
CLOSE spells.txt
END SpellSearcher
BEGIN SpellAdder
OPEN spells.txt for output
READ Spells from spells.txt
DISPLAY “Enter the spell name.”
GET spellName
Spells(Length of spells.txt + 1) = spellName
DISPLAY “Enter the use of the spell.”
GET spellUse
Spells(Length of spells.txt + 1).Use = spellUse
CLOSE spells.txt
END SpellAdder