I'm trying to sort this array in order on C and I'm not getting it right. What I'm doing wrong? The sorted array is wrong, it should be displayed in the below order:
0: boy
1: is
2: right
3: sitting
4: The
5: there.
Thank you all!
int n = sizeof(arr) / sizeof(arr[0]);
int i;
// Print the given array
printf("Given array is\n");
for (i = 0; i < n; i++)
printf("%d: %s \n", i, arr[i]);
// Sort the array
sort(arr, n);
// Print the sorted array
printf("\nSorted array is\n");
for (i = 0; i < n; i++)
printf("%d: %s \n", i, arr[i]);
return 0;
}
Output:
Sorted array is
The
boy
is
right
sitting
there.
Tsorts beforeb.stricmp()if you want case-insensitive comparison.sortcoming from?