P
Pol
Hi all,
I am new to C and don't quite understand why in this example the
pointer "FILE *fp" is not passed back to the calling function with its
new value. In its calling routine it seems to be always pointing to
NULL. Could you explain??
Max
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "stdlib.h"
#include "stdio.h"
int i=0;
static int MyOpen(FILE *fp){
if(fp == NULL) fp=fopen("Test.dat","w+");
printf(" Inside %x \n",(unsigned int) fp);
return 0;
}
int main(){
FILE *fp=NULL;
MyOpen(fp);
printf(" First %x \n",(unsigned int) fp);
MyOpen(fp);
printf(" Second %x \n",(unsigned int) fp);
return 0;
}
I am new to C and don't quite understand why in this example the
pointer "FILE *fp" is not passed back to the calling function with its
new value. In its calling routine it seems to be always pointing to
NULL. Could you explain??
Max
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include "stdlib.h"
#include "stdio.h"
int i=0;
static int MyOpen(FILE *fp){
if(fp == NULL) fp=fopen("Test.dat","w+");
printf(" Inside %x \n",(unsigned int) fp);
return 0;
}
int main(){
FILE *fp=NULL;
MyOpen(fp);
printf(" First %x \n",(unsigned int) fp);
MyOpen(fp);
printf(" Second %x \n",(unsigned int) fp);
return 0;
}