I need to create a function that "points" a file pointer to a particular file in the computer's memory. I was able to do this:
#include <stdio.h>
void abre(FILE*);
void procedimento();
int main ()
{
procedimento();
return 0;
}
void abre(FILE* arq)
{
arq = fopen("testando.txt", "w");
}
void procedimento()
{
FILE* arq = NULL;
abre(arq);
fprintf(arq, "Ola mundo!");
}
The program runs on the terminal, no errors occur. The file is created, but it is left blank. The "fprintf" message is not recorded.
NOTE: First I was doing the code without pointing the file to NULL, however I read that errors occur when you use a pointer without pointing it to some memory address and this really happened. The terminal was locked during execution.