Program Keeps Crashing

I am making a program with Dev-C++ 4.9.9.2. The program is taking a word and writing it backwards. It is not using recursive or anything. Just an array. And the array size is determined by the user. The problem is, when I run the program it crashes. Does anyone know what is wrong?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>

using namespace std;

int main()
{
    int size;
    int size1;
    char word[size];
    cin>>size;
    cin.ignore();
    cin>>word;
    cin.ignore();
    for (size=size1; size1>-1; size1--) {
    cout<<word[size1];
}
    return 0;
}
In line 14:
for (size=size1; size1>-1; size1--) {
You're setting size equal to size1, not vice versa. Since you're changing size1 and not size, then the loop continues infinitely, and since size1 is undeclared, crazy stuff (like crashes) happen.
Instead of for (size=size1; //etc , try for (size1=size //etc .
thanks that helped a lot
it was still crashing but i changed the ints to chars and now it works
the only problem now is that when i type in
5 (for str length)
hello (for str)
it comes up with a bunch of weird symbols and then spaces and then olleh
any idea what that could be?
Topic archived. No new replies allowed.