1
I need to create a function that "points" a file pointer to a particular file in computer 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 empty. "fprintf" message is not saved.
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 it really happened. The terminal would crash during execution.