-
file pointer
O.K. to use a file we first need to open it (make a connection in the form of a stream) this is acheived with fopen which returns a pointer to that file we then assign this returned pointer to a file pointer like so.
FILE *file_ptr;
file_ptr=fopen(filename,"mode");
so fopen returns a pointer which in turn is assigned to our pointer therefore is this a pointer to a pointer if so how come we don't need multiple indirection when declaring our file pointer like so FILE **file_ptr;.
thaks for pointing me in the right direction.
-
If you had 2 integer's (int a and int b) to copy the contents from one integer to another you'd do -
a = b;
If you have two pointers(int* a and int* b) to copy the contents from one to the other you'd do -
a = b;
If this was a pointer to a pointer then the statement would look like -
a = &b;
which wouldn't work because 'a' has been delcared to store the address of an integer, not a pointer.
As fopen() doesn't return the address of a FILE pointer, but the FILE pointer itself then the first case is the one that is carried out.
-
I think fopen returns the address of the file "structure." The value of the address is then assigned to your file pointer, so it is not a pointer to a pointer. It simply contains the address of the file.
-
it returns a pointer, if it stores it into a pointer, no problem!
Oskilian