Experts Exchange connects you with the people and services you need so you can get back to work.
Open in new window
char str = '\0';
std::cout<<"///*** Program for sorting the string with bubble sort using pointers ***///";
std::cout<< std:.endl << "Enter the String: ";
char* temp = new char[len+1];
char * temp = strdup(str); // cares for lenght and makes a copy of str using malloc
std::string temp = str;
for (int i = 0; i < str_length-1; ++i)
for (int j = i+1; j < str_length; ++j)
if ((str[i] > str[j]) // here you may cast to unsigned int to handle negative char codes
var = str[i];
str[i] = str[j];
str[j] = var;
int sort(char* const str, const int strLength, char* result)
int swapOccurred = true;
if (result == NULL)
strncpy(result, str, strLength + 1);
swapOccurred = false;
for (int i = 0; i < strLength - 1; i++)
if (*(result + i + 1) < *(result + i))
char c = *(result + i + 1);
*(result + i + 1) = *(result + i);
*(result + i) = c;
swapOccurred = true;
Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.
Have a better answer? Share it in a comment.
Please enter a first name
Please enter a last name
Must be at least 4 characters long.
Join and Comment
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.
Premium members get this course for $159.20.
Premium members get this course for $167.20.
Premium members get this course for $349.00.
Premium members get this course for $24.99.
Premium members get this course for $108.00.
Premium members get this course for $18.75.