-
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 - [email protected]
****************************************************************************/
#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)
{
}
-
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.
-
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?