I am having an issue with displaying a sorted array.
int main()
{
const int INPUT_SIZE = 81;
char input[INPUT_SIZE];
int selection = 0;
/*Collects a string from the user, and tests for bad input*/
while ((cout << "String: ") && !(cin.getline(input, INPUT_SIZE)) || (strlen(input) > INPUT_SIZE) || (strlen(input) < 2))
{
cout << "Please enter a valid string!\n";
cin.clear();
cin.ignore(150, '\n');
}
/*Shows users string*/
cout << input << endl;
selectionSort(input, INPUT_SIZE);
/*Displays the sorted array for data testing*/
for (int count = 0; count < INPUT_SIZE; count++)
cout << input[count];
cout << endl;
return 0;
}
void selectionSort(char input[], int n)
{
int startScan, minIndex, minValue;
for (startScan = 0; startScan < (n - 1); startScan++)
{
minIndex = startScan;
minValue = input[startScan];
for(int index = startScan + 1; index < n; index++)
{
if (input[index] < minValue)
{
minValue = input[index];
minIndex = index;
}
}
input[minIndex] = input[startScan];
input[startScan] = minValue;
}
}
If the array is not completely filled, there are tons of "junk" elements that will place themselves at the beginning of the cout statment.
For display purposes, is there a way to remove these so that the output is cleaner?
Example:
╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠╠ aaddjjkkls
I need the ╠ elements removed from the output.
I was attempting to add a nested if statement within
the display For loop, but to no avail.
Your advice would be greatly appreciated,
Dominick