Skip to main content
10 events
when toggle format what by license comment
Apr 4, 2016 at 1:36 comment added user11211 Cliff B.? Am I correct in seeing this as one of the main points this exercise is trying to teach us, to never mess with data outside the scope of our own program, ever. Especially don't ever test a condition against it. If so, great lesson cs50!
Apr 4, 2016 at 1:35 comment added user11211 I was very surprised to see how many others besides myself attempted to use this same technique of checking against a condition we believed would never be true which was that there won't be data in that part of the array (board[j + 1] in the case of the blank being furthest to the right). I thought there would be a segmentation fault when I first tried this but indeed, if at the time of your move there is no garbage data there, your condition won't be met and the game will appear to work fine.
Feb 28, 2016 at 16:19 comment added Cliff B If you have the "exact same problem" and the same code, that code is accessing data outside of the array. C doesn't do validation of array indexes and will allow this. The data that you're comparing in these invalid array elements are actually data contained in other variables, random garbage data, or data belonging to other programs. Since you're looking for a 0, it's entirely possible to pass the if test in the code, make the swap and corrupt data on both sides of the trade.
Feb 28, 2016 at 12:07 comment added user10927 Having the exact same problem here... andi still have the same inquiries. Why isn`t the "if" being ignored if the tile is not in that position? And how did you solve the problem anyway?
Feb 23, 2016 at 11:33 comment added Priyanshu Kumawat Thanks anyways it worked....but I'm just curious why if statement is not ignoring if there is no element ? and what exactly is happening there if "if statement" does not ignore ?
Feb 23, 2016 at 11:32 vote accept Priyanshu Kumawat
Feb 23, 2016 at 11:25 comment added Priyanshu Kumawat I put "if statement" there...shouldn't this "board[i+1][j]" be ignored if there is no element
Feb 22, 2016 at 0:52 history undeleted Cliff B
Feb 21, 2016 at 20:42 history deleted Cliff B via Vote
Feb 21, 2016 at 20:42 history answered Cliff B CC BY-SA 3.0