graph seg faults

So iam new to c++ , iam taking it in college right now and iam still very new to it. So my problem is that my program seg faults when i try to create a new char and its the same code from another one of my programs and it works fine there. I hope u guys can help me out . Thanks.
pS: ive written whr it seg faults , and iam just not able to use debuggers all that well. My code isnt probally very good but i hope u guys can get thru it .
THANKS in advance.

//File 1


#include<iostream>
using namespace std ;
#include "CS163_Program5_Hfile.h"

client::client()
{
int num ;
cout<<"Please enter the max number of tasks your going to add " ;
cin>>num;
cin.ignore(100, '\n' ) ;
agraph.graph2(num);
}

int client::add()
{
cout<<"Please enter name of task \n";
char name[100] ;
cin.get( name , 100 ) ;
cin.ignore( 100 , '\n' ) ;

cout<<"Please enter time required \n ";
char time [100] ;
cin.get( time , 100 ) ;
cin.ignore ( 100 , '\n' ) ;

agraph.add( name , time ) ;
}

int client::join()
{
cout<<"its all good " ;
agraph.join();
}

int client::display()
{
agraph.display();
}

int main()
{
client aclient ;
char choice; //We use this local variables to input the users choice
do{ //This loop runs the whole program
cout<<"a to add , d to display , j to search and q to quit ";
cin>>choice;
cin.ignore( 100, '\n' );
cout<<"\n";

if(choice == 'a')
{
aclient.add();
}
else if(choice == 'd')
{
aclient.display();
}
else if(choice == 'j')
{
aclient.join();
}
else if(choice == 'q')
{
cout<<"See ya ";
return(0);
}

else //This happens if the user enters an invalid choice
{
cout<<"Bad choice ";
}
}while(choice != 'q');
}


//File 2



#include<iostream>
using namespace std ;
#include "CS163_Program5_Hfile.h"



int graph::graph2( int asize )
{
size = asize ;
graph = new vertice* [ size ] ;
for ( int i = 0 ; i < size ; ++i )
{
graph [i] = NULL ;
//graph [i] head = NULL ;
}
cout<<asize;
}


int graph::add(char * name , char * time )
{
int i = 0 ;
if(graph[i] != NULL)
{
while( graph[i] = NULL )
{
++i; cout<<"Traverse " ;
}
}
else { cout<<"No traversel" ;}
graph[i]->anoperate.add( name , time ) ;


}

int graph::join()
{
for (int i = 0 ; i < size ; ++ i )
{
cout<<i+1<<" . "<<graph[i] -> anoperate.adata.name <<endl;;
}

int one ,two ;
cout<<"Enter the number corresponding to the name of the task you want to add stuff to ";
cin>>one;

cout<<"Which one to join to this task ";
cin>>two;

if(!graph[one-1]->head)
{
head = new node ;
head -> location = graph[two-1] ;
head -> next = NULL ;
}
else
{
node * to_add;
to_add = graph[one-1]->head;

if(head->next)
{
while(to_add->next)
{
to_add=to_add->next ;
}
}
to_add->location = graph[two-1] ;
to_add->next = NULL ;
}
}

int graph::display()
{
for ( int i = 0 ; i < size ; ++i )
{
graph[i]->anoperate.display();
if(head->next)
{
node * current ;
current = head ;
while(current)
{
current->location->anoperate.display();
current=current->next;
}
}
}
}

graph::~graph()
{
graph = new vertice* [ size ] ;
for ( int i = 0 ; i < size ; ++i )
{
graph [i] = NULL ;
//graph [i] head = NULL ;
}

}


// File 3

#include<iostream>
using namespace std ;
#include "CS163_Program5_Hfile.h"
#include <cstring>

int operate::add ( char * temp_name , char * temp_time )
{ cout<<"Worked till here " ;
cout<<"This is the name : "<< temp_name ;

//Temp_name outputs just fine , so its not that , it seg faults in
//the next line
adata.name = new char [ strlen ( temp_name ) + 1 ] ;
cout<<"Did it make it ? " ;
strcpy( adata.name , temp_name ) ;


adata.time = new char [ strlen ( temp_time ) + 1 ] ;
strcpy ( adata.time , temp_time ) ;
}

int operate::display()
{
cout<<" Name : " << adata.name <<endl << " Time : " << adata.time << endl;
}




//H File




struct data
{
char * name ;
char * time ;
};

class operate
{

public :


int add( char * temp_name , char * temp_time );
int display();

//private :
data adata;
// char * name ;
// char * time ;
};



struct vertice;
struct node
{
vertice * location ;
node * next ;
};



struct vertice
{
operate anoperate ;
node * head ;

};

/*struct node2
{
vertice * location ;
node2 * next ;
*/


class graph
{
public:~graph();
int graph2( int size ) ;
int add( char * name , char * time ) ;
int join();
int display();
private :
int size ;
vertice ** graph ;
node * head ;

};

class client
{
public:
client();
int add();
// int join_display();
int join( /* one , two */ );
int display();
private:
graph agraph ;
};
Topic archived. No new replies allowed.