Thread: Array/Crashing

  1. #1
    Hi ay_okay's Avatar
    Join Date
    Dec 2004
    Location
    Here
    Posts
    69

    Array/Crashing

    I ran this code and it froze on me. So I ran it again and it didn't. I ran it 20 times and it crashed again. I'm using arrays so the compiler doesn't spot these errors. Could you look over my short code?
    Code:
    #include <iostream.h>
    
    int AI_PROCESS(int a[10][10])
    {
        cout<<a[0][0]<<" "<<a[1][0]<<" "<<a[2][0];
        return 0;
    }
    
    int main()
    {
    int board[10][10];
    board[0][0] = 0;
    board[1][0] = 1;
    board[2][0] = 2;
    
    AI_PROCESS(board);
    
    
    cin.get();
    return 0;
    }

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >I ran it 20 times and it crashed again.
    I think your computer's unstable, but:

    >#include <iostream.h>
    You should be using the new style headers:
    Code:
    #include <iostream>
    using namespace std;
    > cout<<a[0][0]<<" "<<a[1][0]<<" "<<a[2][0];
    You might as well flush the output stream here with a endl.
    cout<<a[0][0]<<" "<<a[1][0]<<" "<<a[2][0] << endl;

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    I'm pretty sure that the crashing isn't anything to do with running that code.

    Try being more specific than "it crashes".
    Like for example, the text of the error message(s), screen shots of dialogs, whatever...
    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.

Popular pages Recent additions subscribe to a feed