#include <stdio.h>
#include <stdlib.h>
long file_size(FILE *fp);
int main(void)
{
FILE *fp;
char *buf;
fp = fopen("e:/test.txt", "r");
long fsize = file_size(fp);
buf = (char*) malloc (sizeof(char) * fsize);
if (buf == NULL) {
fputs("Memory error", stderr);
exit (1);
}
fread(buf, 1, fsize, fp);
puts(buf);
fclose(fp);
free(buf);
return 0;
}
long file_size(FILE *fp)
{
fseek (fp , 0 , SEEK_END);
long fsize = ftell(fp);
fseek(fp, 0, SEEK_SET);
return fsize;
}
/*
run:
askljdf aslkd fjalsk dfjas ldf
*/