I have a file that contains calls to functions in my code. Some examples of functions are criar(), inserir(elemento, conjunto), listar(conjunto)
where arguments are integers passed to the function. These functions should be called through arquivo.txt
which will contain, for example:
criar()
inserir(1,0)
listar(0)
To read the file, I used the following function:
void leArquivo(){
FILE *arq;
if((arq = fopen("arquivo.txt", "r")) == NULL)
printf("Erro ao abrir o arquivo.\n");
char buffer[100];
char *p;
while (fscanf (arq, "%s\n", buffer) != EOF) {
p = buffer;
printf("%s\n", p);
}
fclose (arq);
}
However, this only princes the "name" of the function itself, and does not call it. For example, if in the file the function is criar()
, it criar()
and not the return of the create function. I found that since printf("%d", criar());
returns the value of the function, printf("%d\n", p);
would return the same, but not.
I thought of using the strcmp()
function to be able to compare if the names are equal and then call the function, and I succeeded in the functions without arguments, but I do not know how to do for functions of type inserir(elemento, conjunto)
, where it is not possible to "predict" the arguments. Any suggestions on how to call these functions from the file reading?