1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| #include <stdlib.h>
#include <stdio.h>
#include <assert.h>
int fonction(char *chemin)
{
FILE* fic;
size_t size;
char* buffer;
fic = fopen(chemin, "rb");
if(fic == NULL)
{
return EXIT_FAILURE;
}
fseek(fic, 0, SEEK_END); // goes to the end
size = ftell(fic); // gets position (size)
fseek(fic, 0, SEEK_SET); // goes to the file's begining
buffer = malloc((size + 1) *sizeof(char));
fread(buffer, sizeof(char), size, fic);
fclose(fic);
printf("%s",buffer);
return EXIT_SUCCESS;
}
int main(void)
{
return fonction("main.c");
} |
Partager