This exact problem is reviewed in the lectures. In short, you have to use pointers in your swap function. I'm pretty sure it's week 4, 2nd lecture (lecture continued). Or you can check out the lecture notes here: http://d2o9nyf4hwsci4.cloudfront.net/2013/fall/lectures/4/w/notes4w/notes4w.html
void swap(int* a, int* b)
int tmp = *a;
*a = *b;
Don't you want to swap the two tiles? You are swapping 2 new integers that happen to hold the tile values.
Get rid of those 2 extra integers and simply use the tiles themselves in your swap code.
Let's say I wanted to swap 2 values:
int hold = firstValue;
firstValue = secondValue;
secondValue = hold;
In your case firstValue is board[d-1][d-3] so simply ...
You don't need to specify the return type of your function when you call it, only when you declare/define it.
So you've declared the function right, like this: void swap (int* a,int* b)
But when you call it, you have to omit the type specifications, like this: swap(&a,&b);
But what you've done is this: void swap(&a,&b);
TL;DR: remove the ...
It's not really clear what you mean by "swapping elements". I can't see why you'd change one element in a struct, but I can see how you might want to swap entire structs.
Say that you have a struct like this:
Now, say that you have two structs, a and b, and they have been populated ...
You use 0-based indexing (the C standard) in some places (move, won), but 1-based indexing in others (init, draw).
You use a strange variable blank. This variable is initially of undefined value (could even be read before receiving a defined value), and the only value that could ever be assigned to it is 0.
You have an equally strange variable tile_move. ...
Remember that parameters in function call should pass the address of variables like swap(&p, &q);
int tmp = *a;
The value stored at the memory block to which a was pointing, is being stored in tmp
*a = *b;
The pointer a is made to point to where the pointer b was pointing initially. Till now, *a holds the value of pointed by b, *b retains ...
Without completely giving it away:
Why are you assigning 42 to the variable 'tile'? You want to store 42 in the board array, right? Not in the tile variable, right? So, you should be assigning 42 to the board[?][?].
BTW, you don't need the 'temp' variable at all. In the last 4 if() statements you are assigning 'tile' to 'temp' and then straight away 'temp' ...
You are not required to return the two values, what your swap() function is doing is going to where the numbers are stored and subsequently changing them.
*a means go to where a is
temp = *a is take the value from a and store it in temp
*a = *b is take the value from b and store it where a is
this means you don't have to return anything out of ...
The pseudocode for selection sort is as follows
for int i = 0 to i < n - 1, increment i by 1
declare an int named min and set it to i
for int j = i + 1 to j < n, increment j by 1
if values[min] > values[j]
set min to j
swap values[i] and values[min]
You did most of it correctly ...