[ad_1]
When i run my code it runs but it’s return value is not 0. So i tried debugging mode. And the problem is caused by if(yol[i][j]==' ')
part. When compiler comes here, segmentation fault error is shown up. Why is this happening guys?
void randomElma(char yol[32][44]){
srand(time(NULL));
int i,j;
for(i=0;i<32;i++){
for(j=0;j<44;j++){
if(yol[i][j]==' '){
if((rand()%10)==1){
yol[i][j]='O';
}
}
}
}
}
Here is my main function:
int main(int argc, char *argv[]) {
int N=31, M=43;
int i=0, j=0;
char ch;
int map[32][44];
char yol[32][44];
puan=0;
FILE *dosya;
dosya=fopen("harita.txt","r");
while ((ch = fgetc(dosya)) != EOF){
yol[i][j]=ch;
if(ch==' ')
map[i][j]=1;
else
map[i][j]=0;
if(ch=='\n'){
i++; j=0;
}
else{
j++;
}
}
for(i=0;i<31;i++){
for(j=0;j<44;j++){
printf("%d",map[i][j]);
}
printf("\n");
}
fclose(dosya);
map[29][1]=1;
map[29][41]=1;
randomElma(yol[32][44]);
DFS(map,29,1,yol); // 29, 41
return 0;
}
Also i added time.h library
[ad_2]