ANSI C - Filsize ?

From: Joe (amplifymysoul_at_hotmail.com)
Date: 01/31/04


Date: Sat, 31 Jan 2004 19:04:20 +0100

Im quit new to this language so bare with me:

how do read the contens of a textfile in to a buffer?
how do i get the size of a file?

I've tried this, but it dosn't seem to work:

  FILE *file1;
  FILE *file2;
  file1 = fopen("inputfil.txt", "r+");
  file2 = fopen("inputfil.txt", "r+");

  while((c = getc(file1)) != EOF)
  {
        filesize++;
  }

unsigned char buffer[filesize];
                
while((c = getc(file2)) != EOF)
{
            buffer[i] = c;
            for(i = 0; i< filesize-1; i++)
            {
             buffer[i] = getc(file2);
          }
}