Hello,
I'm rather newbie in C programming.
Passing FILE pointer to functions seems to give some problems sometimes. My way to do it is as follow :
Code:
void read_file(FILE **file_pointer);
int main(void)
{
FILE *f_in = NULL;
...
f_in = fopen(<file_name>,"r");
read_file(&f_in);
...
}
void read_file(FILE **file_pointer)
{
char *in_line = (char*) calloc (1000,sizeof(char));
...
fgets(in_line, 1000, *file_pointer);
...
}
The advantage of this way of doing is you can open, read and close your file in separated blocks of code.
If I don't use &f_in as argument, I get a segment fault with fgets.
This is my solution for it. Tell me if you think I'm doing something wrong.
Good day to everyone