0

i have written init and draw function

in init i have made 2 nested loops and given value to each element starting from position (0,0) = d*d-1 till the last element and i have printed the given values using printf function in draw() function. After this when i try to run the program to check its working i get a segmentation fault even though i am not accessing something out of memory.why is this happening?

7
  • what is your loop logic? for instance: for(int i = 0, n = d*d - 1; i < d; i++){for(int j = 0; j < d; j++, n--){}}
    – postylem
    Sep 9 '14 at 10:29
  • @postylem k=d*d-1; for(int i=0;i<d;i++){ for(int j=0;j<d;j++){ b[i][j]=k; k--;} seems same
    – pranav
    Sep 9 '14 at 12:24
  • @postylem i am getting a segmentation fault at b[i][j]=k but why it is representing b[0][0]
    – pranav
    Sep 9 '14 at 14:22
  • that seems good. what you're describing works for me, so I suppose the problem must be something else. hmm. when you declare int b[MAX][MAX], do you have MAX big enough?
    – postylem
    Sep 10 '14 at 13:16
  • @postylem MAX is globally defined with 9.Can there be a problem with my driver or something , should I inform the staff?
    – pranav
    Sep 10 '14 at 20:07

You must log in to answer this question.

Browse other questions tagged .