hi

can anyone tell me why this function works:

int fopenfile(FILE **fp, char *fname)
{
  *fp = fopen(fname, "r+");
  if (!*fp) 
       *fp = fopen(fname, "w+");  /* create if not found */
  
  return 0;
}

but this one doesnt:

int fopenfile(FILE *fp, char *fname)
{
  fp = fopen(fname, "r+");
  if (!fp) 
      fp = fopen(fname, "w+");  /* create if not found */
  
  return 0;
}

any operations i try to do with the file if i opened it with the
second function, cause a segfault, but if i used the first function,
i can read/write to the file no problems.

to me it seems then that the second function is not modifying 'fp' at
all, but why not?  is it possible that the fp is only passed by
value if its declared as FILE *fp?  excuse me if this question is
elementary, but i'm a convert from pascal :).

a short explanation would be appreciated.

thanks,

leon

-- 
                                __   _
Leon Breedt                -o) / /  (_)__  __ ____  __
System Administrator       /\\/ /__/ / _ \/ // /\ \/ /
[EMAIL PROTECTED]        _\_v____/_/_//_/\_,_/ /_/\_\

Linux:  Oh no, I think my 64-bit uptime variable just overflowed

Reply via email to