Файл my_funcs.h
#ifndef MY_FUNCS_H
#define MY_FUNCS_H
typedef struct{
int x;
int y;
int z;
double weight;
}point;
typedef struct{
point *points;
int size;
}space;
point* init_space(int size);
void show_points(space *my_space);
#endif
Файл my_funcs.c
#include "my_funcs.h"
#include <stdlib.h>
point* init_space(int size){
point tmpPoints[size];
for(int i=0; i<=size; i++){
tmpPoints[i].x = -100 + rand() % 100;
tmpPoints[i].y = -100 + rand() % 100;
tmpPoints[i].z = -100 + rand() % 100;
tmpPoints[i].weight = -100 + rand() % 100;
}
space mySpace = {};
mySpace.size = size;
mySpace.points = &tmpPoints;
return &tmpPoints;
}
void show_points(space *my_space){
printf("Function works\n");
printf(my_space -> size);
}
Файл main.c
#include <stdio.h>
#include "my_funcs.h"
#define SIZE_OF_SPACE 5
int main(){
printf("Progarm started...\n");
int size = SIZE_OF_SPACE;
printf("%d%s",size,"\n");
space my_space;
my_space.size = SIZE_OF_SPACE;
my_space.points = init_space(SIZE_OF_SPACE);
printf("%d",my_space.size);
show_points(&my_space);
//printf("YOU ARE HERE!!!!!!\n");
return 0;
}
При вызове функции show_points вылетает следующее: "Ошибка сегментирования (сделан дамп памяти)". Подскажите, пожалуйста, в чем проблема и как это исправить?