嘿伙计,所以我想做一个功课,我不能整天找到我的程序上的致命错误.让我解释一下:首先,你给出行数,col然后数组的单元格(只有"."免费空间和"*"表示矿井,所有行都没有空格)然后发生崩溃.
main(){
int i,col,row,count,N,M,j;
char **p;
printf("Give number of rows\n");
scanf("%d",&N);
printf("Give number of columns\n");
scanf("%d\n",&M);
p=malloc(N*sizeof(char *)); //Saving room for the array
if (p==NULL)
return -1;
for (i=0;i < N ; ++i){
p[i] = malloc (M * sizeof(char));
if (*(p+i) == NULL)
return -1;
}
for (i=0; i< N;++i){
for ( j = 0 ; j < M ;++j)
scanf("%c",&p[i][j]); //Insert "*" for mines and the rest with "."
}
for (row=1; row<= N;++row){ //Here the things get messy …Run Code Online (Sandbox Code Playgroud)