need help: bubblesort in ascending order

Hello
I am trying to build a c++ that reads user input and arrange letters in ascending order.
for example, if the user input: Hello my name is Moe!
the output will be: !aeeehillmmmnoos (ascending order)

my problem is that when i input hello my name is moe
the output will be ehllo (not completing other letters)
also when i change class size to 50, it outputs unknown weird letters.
This is my code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#define CLASS_SIZE 10
#include <stdio.h>
#include <iostream>


void bubbleSortAWriteToB(const char a[], char b[]);

using namespace std;

int main(void){
    int i;

    // initialize array
    char s_letters[CLASS_SIZE];
    char letters[CLASS_SIZE];
    cout << "Enter \n";
    cin >> letters;
    // sort array
    bubbleSortAWriteToB(letters, s_letters);

    // print sorted array

    for (i = 0; i < CLASS_SIZE; i++){
        printf("%c", s_letters[i]);

    }

    return 0;
}
void bubbleSortAWriteToB(const char a[], char b[]){
    char temp;
    int i,j;

    // initialize b array to hold pointers to each element in a
    for (i = 0; i < CLASS_SIZE; i++){
            b[i] = a[i];
        }

        // in-place sort the b array
        for(i = 0; i < CLASS_SIZE; i++){
            for(j = i + 1; j < CLASS_SIZE - 1; j++){
                if(b[j-1] > b[j]){
                    temp = b[j];
                    b[j] = b[j-1];
                    b[j-1] = temp;
                }
            }
        }
    }
cin >> letters; Operator >> will read until first whitespace. If you need whitespaces in you string, use getline.
i have tried the getline command but the program reads it as a function?
still no luck
You are sorting based on the compile time constant CLASS_SIZE.
What if the user entered fewer than that many characters?
You're going to be sorting uninitialized positions in s_letters.
Topic archived. No new replies allowed.