help needed with segmentation fault tried solving a lot please help
i am getting segmentation fault
in the ****************code***************** #include <stdio.h> int ind[1000][1];/*here row or m is 0 and column or n is 1*/ int main() { char field[1000][100][100]; int count=-1,i,j,p,q; while(1) { count+=1; scanf("%d%d",&ind[1][0],&ind[1][1]); if((ind[count][0]==0)&&(ind[count][1]==0)) { break; } for(i=0;i<ind[count][0];i++) { for(j=0;j<ind[count][1];j++) { scanf("%c",&field[count][i][j]); if(field[count][i][j]=='.') { field[count][i][j]+=2; } } } /*processing the output*/ for(i=0;i<ind[count][0];i++) { for(j=0;j<ind[count][1];j++) { if(field[count][i][j]=='*') { continue; } else { for(p=-1;p<=1;p++) { for(q=-1;q<=1;q++) { if(((i+p)<0)||((j+q)<0)) { continue; } else if(((i+p)>ind[count][0])||((j+q)>ind[count][1])) { continue; } else if(field[count][i+p][j+q]=='*') { field[count][i][j]+=1; } } } } } } } for(i=0;i<=count;i++) { printf("Field #%d:",i+1); for(p=0;p<ind[i][0];p++) { for(q=0;q<ind[i][1];q++) { printf("%c ",field[i][p][q]); } printf("\n"); } } return(0); } *******************end of code*********************** could somebody please help |
Please, PLEASE use code tags..
|
scanf("%d%d",&ind[1][0],&ind[1][1]);
Are you just getting a seg fault on this line because you're trying to access element 1 in the second dimension of your array, which only has one element? Of course, if there's only one element, then the only element you can access is 0. |
Answer:
Code:
change this: |
All times are GMT -5. The time now is 01:35 AM. |