c-array giving me junk

I must be doing something wrong because i keep getting junk when i try to output this cstring.

#include <iostream>
#include <cstring>
using namespace std;

int main(){
char word[20];
char word_new[20];
int len;

cout << "Please enter a word now." << endl;
cin.getline(word, 20);
cout << word << endl;

len = strlen(word);
cout << len << endl;

for (int i = 0; i <= len - 1; i++){
for (int j = len - 1; j >= 0; j--){

word[j] = word_new[i];

cout << word_new[i] << endl;


}
}

for (int count = 0; count < len - 1; count++){

cout << word_new[count];

}

cout << "" << endl;

return 0;
}

First time posting here. Thank you
http://www.cplusplus.com/articles/jEywvCM9/

word_ne is completely unassigned and uninitialized when you read from it in the double for loop.

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
#include <iostream>
#include <cstring>
using namespace std;

int main(){
    char word[20];
    char word_new[20];
    int len;

    cout << "Please enter a word now." << endl;
    cin.getline(word, 20);
    cout << word << endl;

    len = strlen(word);
    cout << len << endl;

    for (int i = 0; i < len - 1; i++)
    {
        for (int j = len - 1; j >= 0; j--)
        {
            word[j] = word_new[i];
            cout << word_new[i] << endl;
        }
    }

    for (int count = 0; count < len - 1; count++)
    {
        cout << word_new[count];
    }

    cout << "" << endl;

    return 0;
}
Topic archived. No new replies allowed.