Array Question

This is a discussion on Array Question within the C++ Programming forums, part of the General Programming Boards category; Hi there, just making a small app using an array, although it compiles and runs in the IDE(eclipse) just how ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    27

    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

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,531
    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?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    27
    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

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,531
    Deleting the debug and release directories (unless you've stored some of your own files there), and doing "rebuild all" sometimes helps.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Registered User
    Join Date
    Nov 2007
    Posts
    27
    solved, yes sorry for this thread, i didnt build the release, only debug -.-, again sorry :S

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic Mutli dimensional Array question.
    By fatdunky in forum C Programming
    Replies: 6
    Last Post: 02-22-2006, 06:07 PM
  2. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. array question?
    By correlcj in forum C++ Programming
    Replies: 1
    Last Post: 11-08-2002, 05:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21