39 lines
783 B
C
39 lines
783 B
C
#include <stddef.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
void *get_data(char *filename, size_t block_size, size_t length){
|
|
|
|
FILE *file = fopen(filename, "r");
|
|
if(!file) return NULL;
|
|
|
|
char *length_block = malloc((length * block_size) * sizeof(char));
|
|
if( length_block == NULL){
|
|
fclose(file);
|
|
return NULL;
|
|
}
|
|
int index = 0;
|
|
while(length != 0){
|
|
int tmp_block = block_size;
|
|
while (tmp_block != 0) {
|
|
*(length_block + index) = fgetc(file);
|
|
index ++;
|
|
tmp_block --;
|
|
}
|
|
length --;
|
|
}
|
|
|
|
|
|
fclose(file);
|
|
return length_block;
|
|
}
|
|
/*
|
|
int main()
|
|
{
|
|
void *a = get_data("example.txt", 1, 7);
|
|
printf("%.7s\n", (char *)a); // Prints: Example
|
|
free(a);
|
|
|
|
return 0;
|
|
}*/
|
|
|