Functions seem to require double FILE pointers or argv pointers, because a pointer is being passed from main to the function. Is this correct?
Functions seem to require double FILE pointers or argv pointers, because a pointer is being passed from main to the function. Is this correct?
...ehhh... that depends on the function.
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
I'll try to be clearer. If you pass a pointer from main to a function, applying the & and *, you'd end up with no star in main and two stars in the function. Is this correct?
For FILE pointers, only if you open the file in the function. Otherwise a single pointer is fine.
So two alternatives are
1. open the file in main().
2. Make it the return value:
FILE *Open_File(filename)
I don't really understand what you mean by "end up with 2 stars".
Two stars indicates that it is a "pointer to an array of pointers".
MagosX.com
Give a man a fish and you feed him for a day.
Teach a man to fish and you feed him for a lifetime.
Hi Magos,
As far as I know, two stars means a pointer to a pointer.
> As far as I know, two stars means a pointer to a pointer.
Correct. It commonly is used as an array of pointers, but there is nothing specific that states "This is an array of pointers." Consider the following:
Quzah.Code:#include <stdio.h> int main ( void ) { int variable = 5; int *ptr = &variable; int **ptrptr =&ptr; return printf( "%d %d %d", variable, *ptr, **ptrptr ); }
Hope is the first step on the road to disappointment.
Hi.
char **ptr will access an array such as: char strings[100][80];
So that ptr[6] is the same as strings[6]...
>Functions seem to require double FILE pointers or argv pointers,
>because a pointer is being passed from main to the function. Is
>this correct?
Depends on the function. If you change the pointer, then it is required.
Code:int openfile (FILE **file) { if ((*file = fopen ("file.txt", "r")) == NULL) return FILE_NOT_OPENED; return FILE_OPENED; }