#include <stdio.h>
#include <stdlib.h>
int main () {
FILE * pFile;
long lSize;
char *buffer;
pFile = fopen ( "file.txt" , "rb" );
fseek (pFile , 0 , SEEK_END);
lSize = ftell (pFile);
rewind (pFile);
buffer = (char*) malloc (sizeof(char)*lSize);
if (buffer == NULL) {fputs ("Memory error",stderr); exit (2);}
fread (buffer,1,lSize,pFile);
for(int i = 0; i<=lSize; i++)
printf("%d = %c \n",i ,buffer[i]);
fclose (pFile);
free (buffer);
return 0;
}
|