Debug Yapınca Segmentation Fault Arised Hatası(Acil)
-
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
struct relationship{
struct node *n1;
struct node *n2;
int dist;
};
struct node{
int rnumb;
struct relationship rarray[10];
};
void createrel(struct relationship* relation,struct node* n1,struct node* n2, int d){
//creating relationship which contains two nodes and distance
relation->n1=n1;
relation->n2=n2;
relation->dist=d;
//adding this relationship to the nodes' array list of relationships
int t= n1->rnumb;
n1->rarray[t]=*relation;
n1->rnumb++;
t= n2->rnumb;
n2->rarray[t]=*relation;
n2->rnumb++;
}
int main(int argc, char *argv[])
{
FILE *file;
char filename[50];
int non,noe,i,j,k,n;
int a,b,c;
int *x,*y,*d;
struct node *nodes;
struct relationship *relations;
gets(filename);
file = fopen(filename,"r"); //dosyayı açıyo
fscanf(file,"%d",&non); //number of nodes
fscanf(file,"%d",&noe); //number of edges-relations-
x=(int *)malloc(noe*sizeof(int));
y=(int *)malloc(noe*sizeof(int));
d=(int *)malloc(noe*sizeof(int));
for(i=0;i<noe;i++){
fscanf(file,"%d",&x[i]); // bu xleri tutuyo
fscanf(file,"%d",&y[i]); // bu yleri
fscanf(file,"%d",&d[i]); // bu da dleri
}
nodes=(struct node*)malloc(non*sizeof(struct node));
relations=(struct relationship*)malloc(noe*sizeof(struct relationship));
for(n=0;n<noe;n++){
a=x[n]-1;
b=y[n]-1;
c=d[n]-1;
createrel(&relations[n],&nodes[a],&nodes[b],c);
}
printf("%d", relations[0].dist);
printf("Press ENTER to continue...\n");
getchar();
return 0;
}debug yapınca segmentation fault arised diyor ...... yardımcı olabilecek müridler var mı acil....
