There is a possibility of saving data to a file in .txt in VisualG!
VisuAlg allows the storage of data in a text file, obtaining the data when executing the leia
commands.
This feature works as follows:
(Second this font )
If the specified named file does not exist, VisuAlg will
reading data by typing, storing the data read in this
in the order they are provided.
If the file exists, VisuAlg will get the data from this file until it arrives
to its end. From there, you will do the data readings by typing.
Only one file command can be used in each pseudocode, and it
should be in the declarations section (depending on the "success" of this
feature, in future versions it can be improved ...).
If a path is not provided, VisuAlg will look for this file
in the current working folder (usually it is the folder where the program
VISUALG.EXE is). This command does not provide for a default extension; therefore, the
The filename specification must be complete, including with your
extension
(for example, .txt, .dat, etc.).
The syntax of the command is:
arquivo < nome-de-arquivo >
<nome-de-arquivo>
is a constant character (in double quotation marks). See the following example:
algoritmo "lendo do arquivo"
arquivo "teste.txt"
var x,y: inteiro
inicio
para x de 1 ate 5 faca
leia (y)
fimpara
fimalgoritmo
EXTRA
Your variables can also be stored in an array of type type and test it in the query and implement the code with a menu. (With registration and query)
algoritmo "lendo do arquivo"
arquivo "teste.txt"
var x,y,i,j: inteiro
char opcao
vetor mat[5][5]
inicio
repita
escreval("MENU")
escreval("A- GRAVAR ARQUIVOS")
escreval("B- PROCURAR ARQUIVOS")
escreval("s-Sair")
escolha(opcao)
caso 'A'
escreval("Leia matriz:")
para i de 1 ate 5 faca
para j de 1 ate 5 faca
leia(m[i][j])
fimpara
fimpara
caso 'B'
// compare com a variável que quiser
leia(x)
para i de 1 ate 5 faca
para j de 1 ate 5 faca
se(x=m[i][j]) entao
...
fimse
fimpara
fimpara
ate(opcao='s')
fimescolha
fimalgoritmo
You can use the file command, however, it may not be the best option.
For each command leia()
that VisuAlg finds, it will be reading this file and playing in the variable that is in leia()
. Translating ... While not reaching the end of the file, all leia()
is directed to the file ... it will not be possible to read any user data via keyboard while the file does not finish.
If it is to be deployed with a file, always remember the cleanup command might be useful.