Home > Programming > Functions using the "C" programming language > example23.c |
/*
In this example we demonstrate how to pass a pointer to a file pointer
as
function parameter
*/
#include <conio.h> // for getch()
#include <stdio.h> // for
FILE,fopen(),fclose & printf()
/*
This program examines whether a file exists.
*/
/*
Function prototype. Notice the FILE ** declareation
*/
int openfile( FILE **, char
*, char *);
void main(void)
{
FILE *fp; /* File pointer variable */
char s[128];
printf("Please type the filename to check : ");
scanf("%s",s);
if (openfile( &fp, s, "r" ))
{
fclose(fp);
printf("OK. The file %s
exists.\n",s);
}
else
printf("The file %s does not
exist.\n",s);
getch();
}
/*
Function openfile source code.
*/
int openfile( FILE ** fpp, char
*n, char *m )
{
return ( *fpp = fopen( n, m ) ) != NULL;
}
© 2004 Jim Valavanis