Are you certain that what you are doing is a bubble sort? All of the implementations that I have seen use simple swapping between two array elements rather than comparing a copy of the input to the original.
e.g.
int sort(char* const str, const int strLength, char* result){ int swapOccurred = true; if (result == NULL) { return false; } strncpy(result, str, strLength + 1); while (swapOccurred) { swapOccurred = false; for (int i = 0; i < strLength - 1; i++) { if (*(result + i + 1) < *(result + i)) { char c = *(result + i + 1); // SWAP *(result + i + 1) = *(result + i); *(result + i) = c; swapOccurred = true; } } } return true;}
e.g.
Open in new window