Good afternoon, I'm having trouble creating a program that will increase the size of a designated list structure, similar to an array, whenever the occupancy rate of this list is more than 80% filled, I would like to increase it 2 times the size, using realloc, my problem is that I can not get more than 30 elements from the list, if in the while is i < 30 or another higher number starts to go wrong (Segmentation fault) I would like to know why, thank you.
#include "buffer.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
Buff init_buff() {
int i = 0;
Buff x = malloc(sizeof(struct buff));
x - > size = 1;
x - > used = 0;
x - > lis = malloc(sizeof(struct lista));
while (i < 10) {
if (i % 2 == 0) x = load_buffer(x, "par");
else x = load_buffer(x, "impar");
i++;
}
return x;
}
Buff load_buffer(Buff x, char * l) {
float taxa_ocupacao = x - > used / x - > size;
//primeiro caso
if (taxa_ocupacao > 0.8 || taxa_ocupacao == 0) {
x - > lis = realloc(x - > lis, x - > size * 2 * (sizeof(struct lista)));
x - > size *= 2;
}
x - > lis[x - > used].phrase = l;
x - > used++;
return x;
}