I am having some problems with my code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
void union1(int belongs[],int c1,int c2, int n);
int main()
{
int i=0;
int j=0;
int N, num_AERO, num_E;
if (scanf("%d", &N) != 1) { exit(1); }
if (scanf("%d", &num_AERO) != 1) { exit(1); }
int custoAERO[num_AERO];
for (i = 0; i < num_AERO; i++)
{
int id_aero, cst_aero;
if (scanf("%d %d", &id_aero, &cst_aero) != 2) { exit(1); }
custoAERO[i] = cst_aero;
}
if (scanf("%d", &num_E) != 1) { exit(1); }
int *matriz_estradas[N];
for (i = 0; i < N; i++)
{
matriz_estradas[i] = malloc(sizeof(*matriz_estradas[i]));
}
int cid_a, cid_b, cust;
for(i=0; i< num_E; i++)
{
if (scanf("%d %d %d", &cid_a, &cid_b, &cust) != 3) { exit(1); }
matriz_estradas[cid_a -1][cid_b -1] = cust;
matriz_estradas[cid_b -1][cid_a -1] = cust;
}
for(i=0; i<N; i++)
{
int cidade_sozinha = 0;
for(j=0; j<N; j++)
{
if(matriz_estradas[i][j]>0 || matriz_estradas[j][i]>0)
cidade_sozinha = 1;
}
if(cidade_sozinha==0)
{
if((sizeof(custoAERO)/sizeof(int))<i+1)
{
printf("Insuficiente\n");
return EXIT_SUCCESS;
}
}
}
The code works fine, but when the value of N is too high, I get a segmentation fault error when alloc'ing in
for (i = 0; i < N; i++)
{
matriz_estradas[i] = malloc(sizeof(*matriz_estradas[i]));
}
Is there a maximum of memory I can alloc in an array?