I need the comparisons number not swaps, so what did I do wrong really?
I see, okay. In the case where you need to swap you count the first comparison twice. You could change it by having a comp function that increments the counter or only incrementing in case the while loop does not execute.
The first option could be
inline int comp(int x, int y, int * c) {
*c += 1;
return x < y;
}
void insertionSort(unsigned int *arr, int n)
{
int i,j,x,t;
int comparisons=0;
for (i=1;i<n;i++)
{
x = arr[i];
j = i-1;
while (j>=0 && comp(x, arr[j], &comparisons))
{
arr[j+1] = arr[j];
j = j-1;
}
arr[j+1] = x;
}
printf("Comparisons: %d\n",comparisons);
}