This repository has been archived on 2026-05-11. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
2026-02-23 01:15:30 +01:00

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;
}*/