Thread: how to troubleshoot core dumped (aborted) message

  1. #1
    Registered User zolfaghar's Avatar
    Join Date
    Mar 2016
    Posts
    95

    how to troubleshoot core dumped (aborted) message

    This program seemed to run fine the first time, but now it gives me a core dumped program aborted error which I do not understand why.
    Here is the code:

    Code:
    #include <stdio.h>
    
    int main ()
    {
      int a[25], i, j, m, t;
    
      printf ("\nEnter 25 numbers \n");
      
      for (i=0; i<=24; i++)
      {
    
        scanf ("%d", &a[i]);
    
      }
    
      for (i=0; i<=24; i++)
        {
    
          for (j=0; j<=24-i; j++)
            {
    
              if (a[j] > a[j+1]) 
                {
    
                   t=a[j];
                   a[j]=a[j+1];
                   a[j+1]=t;
    
                }
    
            }
    
        }
       printf ("\n  The sort list is \n");
       for (i=0; i<=24; i++)
          printf ("%d", a[i]);
    }
    In order to run the program, I created a data file contained 1 - 25 on each line and I would feed it to my executable as such:

    ./buble < data

    I have attached the data file to the question. I tried to used gdb, but am not sure how to use redirection within gdb.

  2. #2
    Registered User
    Join Date
    Jun 2015
    Posts
    1,643
    In the following line, what will the values of j and j+1 be when i is 0 and j reaches its maximum?
    Code:
              if (a[j] > a[j+1])
    In order to "troubleshoot" (not a bad word, but we usually say "debug") your program you can run it under a debugger such as gdb. gdb will show you the line that causes the segfault and you can examine the values of the variables at that point.

    BTW, the common idiom in C is to write loops like this:
    Code:
      for (i = 0; i < 25; i++)      // not i <= 24, although it amounts to the same thing
    And it would be better to have a define for the size:
    Code:
    #define SIZE 25
    ...
      for (i = 0; i < SIZE; i++)
    ...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Segmentation fault (core dumped) message plus other questions
    By strawberrykikwi in forum C Programming
    Replies: 3
    Last Post: 12-16-2015, 02:21 AM
  2. Replies: 2
    Last Post: 09-21-2015, 11:21 AM
  3. Pthread and malloc -Aborted (core dumped)
    By Hassan Ahmed in forum C Programming
    Replies: 11
    Last Post: 07-12-2013, 11:24 PM
  4. Segmentation fault (core dumped) message
    By pye168 in forum C Programming
    Replies: 11
    Last Post: 12-10-2012, 01:22 PM
  5. Aborted (core dumped)? Error when running
    By Brian Justice in forum C++ Programming
    Replies: 8
    Last Post: 05-19-2012, 10:35 PM