-
Array Question
Hi there, just making a small app using an array, although it compiles and runs in the IDE(eclipse) just how i want it to, when i try run the app in a bash shell i get:
Code:
:~/workspace/Reverse Array/Release$ ./ReverseArray
Please enter a number: 1
Please enter a number: 2
Please enter a number: 3
Please enter a number: 4
Please enter a number: 5
Segmentation fault (core dumped)
here is my code:
Code:
#include<iostream>
using namespace std;
int main()
{
int nArray[5];
for(int x=0;x<5;x++)
{
cout << "\nPlease enter a number: ";
cin >> nArray[x];
}
cout << "\nYour numbers are: " << nArray[0] << nArray[1] << nArray[2] << nArray[3] << nArray[4];
return 0;
}
sorry for this question, because i know to everyone this is apparent but i just cant figure this out for some reason :S
-PS, take no notice of the app title "Reverse Array" ill change the order once this bug is fixed
-
Dunno, it looks OK and runs OK just fine here
Code:
$ g++ foo.cpp
$ cat foo.cpp
#include<iostream>
using namespace std;
int main()
{
int nArray[5];
for(int x=0;x<5;x++)
{
cout << "\nPlease enter a number: ";
cin >> nArray[x];
}
cout << "\nYour numbers are: " << nArray[0] << nArray[1] << nArray[2] << nArray[3] << nArray[4];
return 0;
}
$ ./a.exe
Please enter a number: 1
Please enter a number: 2
Please enter a number: 3
Please enter a number: 4
Please enter a number: 5
Your numbers are: 12345$
Are you sure you're not compiling the debug version, but still running a slightly older (and buggy) release version?
-
my compiler details:
Eclipse Platform
Version: 3.3.1.1
Build id: M20071023-1652
(c) Copyright Eclipse contributors and others 2000, 2007. All rights reserved.
Visit http://www.eclipse.org/platform
This product includes software developed by the
Apache Software Foundation http://www.apache.org/
its always worked fine until i tried the code in the first post :S (using on ubuntu 7.10)
Mind you the compiler works perfectly, it just refuses to budge in the bash shell
-
Deleting the debug and release directories (unless you've stored some of your own files there), and doing "rebuild all" sometimes helps.
-
solved, yes sorry for this thread, i didnt build the release, only debug -.-, again sorry :S