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";
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 ) ;
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 ;
};