Thread: Does anyone know what Error while dumping state(probably corrupted stack) mean?

  1. #1
    Registered User
    Join Date
    Dec 2012
    Location
    Fort Walton Beach, Florida, United States
    Posts
    6

    Does anyone know what Error while dumping state(probably corrupted stack) mean?

    I just created this simple array and compiled it and ran it once it was finished I received this error message:

    3 [main] a 6196 exception::handle: Error while dumping state (probably corrupted stack)
    Segmentation fault (core dumped)

    I am running Cygwin on Windows 7 64bit.

    Code:
    /* One Dimensional Array Source Code*\
    
    #include <stdio.h>
    
    main()
    {
    //Declare and Initialize Variables
    int iArray[] = {0};
    int iX = 0;
    int iNum = 0;
    int iCount = 0;
    
    //Input Data Module
                
                printf("\n Enter a number:");
                printf("\n Enter 0 when done:");
                scanf("%d", &iNum);
                        
            while (iNum != 0)
            {
                iArray[iX] = iNum;
                iX ++;            
                printf("\n Enter a number:");
                printf("\n Enter 0 when done:");
                scanf("%d", &iNum);
                iCount++;
                            
            }//end while
            
                
    //Display Data Module
              
            for  (iX= 0; iX <= (iCount -1); iX++)
            {
                printf("%d\n", iArray[iX] );
                iX = iX ++;
            
            }//end for
            
            return 0;
            
            
    }//end program

  2. #2
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    Code:
    int iArray[] = {0};
    How many elements does this array have?

  3. #3
    Registered User
    Join Date
    Dec 2012
    Location
    Fort Walton Beach, Florida, United States
    Posts
    6
    It is defined by the user.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > It is defined by the user.
    No, it's defined by the compiler to be one element long.

    If you want a variable length array, you need to look into using malloc() and perhaps realloc()

    > iX = iX ++;
    Just remove this, you're already incrementing iX in the loop construct itself.
    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.

  5. #5
    Registered User
    Join Date
    Dec 2012
    Location
    Fort Walton Beach, Florida, United States
    Posts
    6
    Quote Originally Posted by Salem View Post
    > It is defined by the user.
    No, it's defined by the compiler to be one element long.

    If you want a variable length array, you need to look into using malloc() and perhaps realloc()

    > iX = iX ++;
    Just remove this, you're already incrementing iX in the loop construct itself.
    > How do you define an array if you don't know how many numbers the user will enter?
    I'm sorry to ask but I am in an intro to programming class.
    What is malloc() and realloc()?

    Thanks so much..

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by asallen08 View Post
    What is malloc() and realloc()?
    Have you followed Salem's advice to "look into" them? If so, what have you learned?

    There is plenty of information readily available about them, without having to ask people in a forum to explain them again.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  7. #7
    Registered User
    Join Date
    Dec 2012
    Location
    Fort Walton Beach, Florida, United States
    Posts
    6
    Quote Originally Posted by grumpy View Post
    Have you followed Salem's advice to "look into" them? If so, what have you learned?

    There is plenty of information readily available about them, without having to ask people in a forum to explain them again.

    I'm sorry I will look into them. Thanks for the advise. So the error message I was receiving is due the the array not being defined.

    I really appreciate all your help.

    Thanks.

  8. #8
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by asallen08 View Post
    So the error message I was receiving is due the the array not being defined.
    No. The array is defined, and initialised with exactly one element. That is not a problem in itself.

    However, your code later attempts to modify more than one element of that one-element array. That is a probable cause of the error message you received. Strictly speaking, anything is allowed to happen when you do that: an error message and program crash is just as correct as any other possible consequence.

    One way to correct the problem is to increase the number of elements in the array. Another way is to only access the first element of that one-element array.
    Last edited by grumpy; 12-12-2012 at 12:06 AM.
    Right 98% of the time, and don't care about the other 3%.

    If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    > I'm sorry to ask but I am in an intro to programming class.
    Please confirm with your tutor that you are supposed to deal with any length of input, or can assume say a maximum of 100 integers.

    It greatly simplifies the solution (down to beginner level) if you can make this assumption.
    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

Similar Threads

  1. Replies: 9
    Last Post: 09-14-2010, 07:16 AM
  2. stack getting corrupted....
    By roaan in forum C Programming
    Replies: 5
    Last Post: 08-16-2009, 12:43 AM
  3. Array of pointers - stack dumping
    By steve1_rm in forum C Programming
    Replies: 3
    Last Post: 06-04-2009, 10:21 PM
  4. corrupted stack
    By samuelanonymous in forum C Programming
    Replies: 9
    Last Post: 11-22-2007, 08:32 AM
  5. corrupted stack?
    By engineer331 in forum C Programming
    Replies: 3
    Last Post: 09-11-2006, 05:28 AM

Tags for this Thread