N
nergal
Hi,
I've been staring myself blind on the same little code now and I cant
see the problem. The filepointer seems to not change when I open it in
a function.
I've written like this (a bit pseudo here):
void func(FILE* file)
{
/* print addr of file (2)*/
file = fopen("thefile", "wb"); /* open as binary */
/* print addr of file (3)*/
}
void callingFunc(void)
{
FILE* fileptr;
/* print addr of fileptr (1)*/
func(fileptr);
/* print addr of fileptr again (4) */
}
(1) Fileptr address becomes XXX
(2) File addr becomes XXX
(3) File addr becomes YYY
(4) File addr becomes XXX
The correct address of the file pointer must be YYY since its in that
function I open it. But why doesn't it change in the calling function
since I send in a pointer?
Regards,
Nergal
I've been staring myself blind on the same little code now and I cant
see the problem. The filepointer seems to not change when I open it in
a function.
I've written like this (a bit pseudo here):
void func(FILE* file)
{
/* print addr of file (2)*/
file = fopen("thefile", "wb"); /* open as binary */
/* print addr of file (3)*/
}
void callingFunc(void)
{
FILE* fileptr;
/* print addr of fileptr (1)*/
func(fileptr);
/* print addr of fileptr again (4) */
}
(1) Fileptr address becomes XXX
(2) File addr becomes XXX
(3) File addr becomes YYY
(4) File addr becomes XXX
The correct address of the file pointer must be YYY since its in that
function I open it. But why doesn't it change in the calling function
since I send in a pointer?
Regards,
Nergal