I, for whatever reason, get a seg fault when ever I do
I also find that when I try the following I get a seg fault as well.
Code:
soil -> root = (struct entry *) malloc (sizeof(struct entry));
My current hypothesis is that the server I am using will not allow me to access its memory for whatever reason. Though I have tried other programs, and they work just fine, even though they need access to memory. But before my server went down for about 6 hours, everything was just fine upto linking a Binary tree (which I'll have another thread for).
Here is what my code looks like up to the seg fault:
Code:
/////////////////////////////////////////////////////////////////////
// Program : Lab05
// File : lab05h.c
// Function : header
// Description : Header file for Lab05
/////////////////////////////////////////////////////////////////////
# include <ctype.h>
# include <stdio.h>
# include <string.h>
# include <stdlib.h>
# define TRUE 1
# define FALSE 0
# define YES 1
# define NO 0
# define WORD 32
# define MAX 81
# define REMOVE "\\\"\%/`~!@#$^&*()-+={}|[];<>?: "
//Used for strtok ",.' " not included
struct entry{
char name [WORD];
char *line[5] ;
struct entry *left;;
struct entry *right;;
};
struct head{
struct entry *root;
};
int promptFile( char scriptFile[] );
int buildTree ( struct head *soil, FILE *fp );
int fileOpen ( char fileName[], FILE **fpr );
FILE *skipEntry( FILE ***fp );
void upperAll ( char word[] );
FILE *leafAdd ( char name [ ], FILE **fp, struct head *soil );
FILE *addLoop( struct entry **current, FILE ***fp, char line[]);
void displayTree ( struct entry *current );
/////////////////////////////////////////////////////////////////////
// Program : Lab05
// File : main.c
// Function : main
// Description : This program will hold company names and details
// : within a binary tree.
// Variable Ref : soil - holds root of tree
// : fpr - the file to be read in
// : fileName - name of file to use
// : argc - number of arguments read in
// : argv - arguments read in
/////////////////////////////////////////////////////////////////////
# include "lab05.h"
int main( int argc, char *argv[] ){
struct head *soil;
struct entry *current;
char fileName [WORD];
FILE *fpr;
// If file name supplied in command line, build from that file, else
// build from defult file
soil -> root = NULL;
/* REST OF CODE */