Wednesday, September 22, 2010

open a file

I've been doing a lot of reading, so now I'll do a bit of doing.

int main()
{
FILE *plxfilepointer = fopen("test.plx", "rb");

if (plxfilepointer == NULL)
{
printf("No File Found\n\n");
return 0; // bail out of main() AKA end program
}

printf("Found File at %p\n\n", plxfilepointer);

fclose(plxfilepointer);

return 0;

}

Ok, so this does basically what it says, fair enough. My issue is this: I don't want to do it in the main function block. I'd rather pass the responsibility of opening the file to another function, and then have other functions for reading things from the file. I have an idea how to pull this off, but it really depends on how fopen() works under the hood. Seeing whether or not it returns null isn't good enough for testing how it all works, so I'll have to flesh out the program to at least read in some header info from the file.

No comments:

Post a Comment