Hi All,

I would like to simplify some of my code to handle the opening and writing of files. Currently, every time I open or write a file, I have the code right there in the program. I'd like to write two functions (readfile, writefile) so that I save space, and can reuse this code.

First, to open a file, I would like to pass to it a file name to open. How can I do this? Pass a char array? How would I do this. Say I want to open a file named "file.txt"?

Currently, I use this method to open a file:

Code:
unsigned int array[200][200][10];

  if (!(file = fopen("text.txt","rb"))){
    exit(1);
  }
  fread(array, sizeof(unsigned char), filesize, file);
  fclose(file);

// with this, my array is filled with the file contents...

OPENFILE()

How do I get the file name from a passed character array into the "text.txt" place? Or, can I just say:
Code:
openfile("file.txt");

or

openfile(filename[]);

Then, I want this function to return a 3 dimensional array of the contents from that file, say.. array[200][200][10]. How would I pass this back? In the openfile function go:
Code:
return array[][][];
And what call do I make in my code? Do I do something like:
Code:
array[][][] = openfile(filename[]);

WRITEFILE()

Then, I will do some processing on this 3 dimensional array, and then I want to pass the array and a file name to a "write file" function. How can I pass the array, and the file name (array?) and have that function write the file.

Do I do something like:
Code:
writefile(array[][][], filename[]);

I know how to do the file handlng as I already have the code for it.