34 lines
549 B
C
34 lines
549 B
C
|
#include <stdlib.h>
|
||
|
#include <stdio.h>
|
||
|
|
||
|
FILE *fd;
|
||
|
size_t file_sz;
|
||
|
char* file_cnt;
|
||
|
|
||
|
int main(int argc, char *argv[])
|
||
|
{
|
||
|
while(argc--){
|
||
|
|
||
|
const char* filename = *argv++;
|
||
|
fd = fopen(filename, "r");
|
||
|
if(fd == NULL){
|
||
|
fprintf(stderr, "couldn't open this file: %s\n", filename);
|
||
|
continue;
|
||
|
}
|
||
|
|
||
|
// get file size
|
||
|
fseek(fd, 0, SEEK_END);
|
||
|
file_sz = ftell(fd);
|
||
|
rewind(fd);
|
||
|
|
||
|
file_cnt = malloc(sizeof(char)*file_sz);
|
||
|
fread(file_cnt, sizeof(char), file_sz, fd);
|
||
|
|
||
|
printf("%s\n", file_cnt);
|
||
|
|
||
|
free(file_cnt);
|
||
|
fclose(fd);
|
||
|
}
|
||
|
return 0;
|
||
|
}
|