segmentation fault

This is a discussion on segmentation fault within the C Programming forums, part of the General Programming Boards category; hey guys i have segmentation fault within this code somewhere what is the problem does anyone know? I dont think ...

  1. #1
    Musicman - Canora
    Join Date
    Aug 2005
    Location
    Melbourne
    Posts
    252

    segmentation fault

    hey guys i have segmentation fault within this code somewhere what is the problem does anyone know? I dont think there is any memory leaks


    Code:
    /****************************************************************************
    * COSC1098/1283 - Assignment #2 - Tennis Store
    * Programming Principles 2A/Programming Techniques
    * Author           : <insert name here>
    * Student Number   : <insert student number here>
    * Yallara Username : <insert username here>
    * Start up code provided by Steven Burrows - stburrow@cs.rmit.edu.au
    ****************************************************************************/
    
    #include "ts.h"
    #include "ts_utility.h"
    #include "ts_options.h"
    
    /****************************************************************************
    * Function readRestOfLine() is used for buffer clearing. Source: 
    * https://inside.cs.rmit.edu.au/~pmcd/teaching/C-Prog/CourseDocuments/
    * FrequentlyAskedQuestions/
    ****************************************************************************/
    void readRestOfLine()
    {
       int c;
    
       /* Read until the end of the line or end-of-file. */   
       while ((c = fgetc(stdin)) != '\n' && c != EOF)
          ;
    
       /* Clear the error and end-of-file flags. */
       clearerr(stdin);
    }
    
    /****************************************************************************
    * Initialises the system to a safe empty state.
    ****************************************************************************/
    void systemInit(TennisStoreType* ts)
    {
    }
    
    /****************************************************************************
    * Loads all data into the system.
    ****************************************************************************/
    void loadData(TennisStoreType* ts, char* customerFile, char* stockFile)
    {
    
      /* declaration of variables*/
      char* stockID;
      char* description;
      char* custID;
      char* surname;
      char* firstname;
      char* address;
      char* suburb;
    
      double unitprice;
      int stocklevel;  
      int postcode;
      int phone;
    
    
    }
    
    /****************************************************************************
    * Deallocates memory used in the program.
    ****************************************************************************/
    void systemFree(TennisStoreType* ts)
    {
    }

  2. #2
    cwr
    cwr is offline
    Registered Luser cwr's Avatar
    Join Date
    Jul 2005
    Location
    Sydney, Australia
    Posts
    868
    The skeletal code you posted does practically nothing, and has no main function so isn't a complete program. Post the code that is causing the segmentation fault.

    Also, a memory leak is when you allocate memory and forget to free it. This is not a likely cause for a segmentation fault. Segmentation faults occur when you attempt access (read or write) memory that doesn't belong to your process. Some, but not all, causes are: stack overflow, buffer overflow, following a null pointer, following an uninitialised pointer, etc.

  3. #3
    Wannabe Coding God
    Join Date
    Mar 2003
    Posts
    259
    if you deallocate your memory twice it will also cause a segmentation fault, since you posted about worrying about memory leaks, maybe you're freeing your memory twice?
    They say that if you play a Windows Install CD backwords, you hear satanic messages. That's nothing; play it forward and it installs Windows.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why am I getting segmentation fault on this?
    By arya6000 in forum C++ Programming
    Replies: 6
    Last Post: 10-12-2008, 06:32 AM
  2. Segmentation fault
    By bennyandthejets in forum C++ Programming
    Replies: 7
    Last Post: 09-07-2005, 05:04 PM
  3. Segmentation fault
    By NoUse in forum C Programming
    Replies: 4
    Last Post: 03-26-2005, 02:29 PM
  4. Locating A Segmentation Fault
    By Stack Overflow in forum C Programming
    Replies: 12
    Last Post: 12-14-2004, 12:33 PM
  5. Segmentation fault...
    By alvifarooq in forum C++ Programming
    Replies: 14
    Last Post: 09-26-2004, 12:53 PM

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