I'm little bit confused over here, not quite sure about this. What I'm trying to do is to pass the name of a file through terminal/cmd that will be opened and read from.
myfunction(char* fileName, FILE* readFile)
{
if((readFile = fopen(fileName,"r")) == NULL)
{
return FILE_ERROR;
}
return FILE_NO_ERROR;
}
int main(int argc, char **argv)
{
FILE* openReadFile;
if(myfunction(argv[1], openReadFile) != FILE_NO_ERROR)
{
printf("\n %s : ERROR opening file. \n", __FUNCTION__);
}
}
My question is if i pass a pointer openReadFile to myfunction() will a readFile pointer to opened file be saved into openReadFile pointer or do i need to put *readFile when opening.
&openReadFileinto the function if you want the updated pointer passed back to the caller. The parameter declaration of the function would beFILE** readFileNULL.main()you can't, because it's pointer value is lost after the function returns.