The problem is that when executing the program it produces a segment violation and I can not find the reason why. The goal is to reach the "error detectado en la tabla"
line
#include <stdio.h>
#include <stdlib.h>
#define SIZE 1000
struct data_unit{
int data;
struct data_unit *next;
};
typedef struct data_unit unit, *unit_ptr;
void function(unit_ptr table){
int y;
for (y = 0; y <SIZE-1; y++)
{
table[y].data = y;
table[y].next = &table[y + 1];
}
table[SIZE - 1].data = SIZE - 1;
}
int check(unit_ptr table){
int y;
for (y = 0; y < SIZE; y++)
{
if ((table[y].data + 1) != table[y].next->data){
return 1;
}
}
return 0;
}
int main(int argc, char **argv)
{
unit_ptr buf;
buf = (unit_ptr)calloc(SIZE, sizeof(unit_ptr));
function(buf);
if (check(buf))
{
printf("Error detectado en tabla\n");
}
free(buf);
return 0;
}