int openfile(FILE **fp,char filename)
fp = fopen(filename,"r");
while( (ch = fgetc(fp)) != EOF )
Is this a correct way to open a file from a function ?
It depends what you are trying to do. However, it would be more sensible for the file pointer to be internal to the function. Also
openfile is a bit ambiguous as a name since the function opens and processes the file; why does it not also close it?
A better structure would be to send just the filename into the function, and let it return the file pointer. You can then pass that pointer to other functions to process the file. Alternatively, your function could open the file, read all the data from the file into a memory buffer or set of objects, close the file, and just return the memory.
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)