Hi guys!!!
everytime I try to read the course description from the file it crashes, (fin>>Des; (*cptr).setclassD(Des);) I even used the getline function and still not workling ... maybe this a very easy fix but I have been trying to fix it for hours and now I'm turning to you guys . the test file should look like " CPE 202 Introduction to computer "
any thought would be great thanks a lot

#include <iostream>
#include <stdlib.h>
#include <fstream>
using namespace std;

class course
  {
	public:
     course ();//constructor
    ~course();//destructor 
      
        
	void setdept(char *);
	char * getdept();

	void setcode(int);
	int  getcode();
   
    void setclassD(char * );
    char * getclassD();
    void print() const ;


    private:
            
	char * dept;
	int   code;
    char * classD;
		
 };

course::course()
{
dept = new char [20];
dept[0]= '\0';
code = 0;
}

course::~course()
{
delete [] dept;
dept = '\0';
code = 0;


}

 void course::setdept(char* dpt)
 {
	int i = 0;
	while(dpt[i]!='\0')
        {
		dept[i]=dpt[i];
		i++;
	}
	dept[i] = '\0';

 }
 void course::setcode(int kode)
 {
	code = kode;
 }

 char* course::getdept()
 {
	return dept;
 }
int course::getcode()
{	
	return code;
}

void course::setclassD(char * Des)
{
    

	int i = 0;
	while(Des[i]!='\0')
        {
		classD[i]=Des[i];
		i++;
	}
	classD[i] = '\0';

}

char * course::getclassD()
{

 return classD;
 }

 int main()
  {	
//declaration 
       ifstream fin;
        int NUM=1; 
        int i;
        int kode;
        course * cptr;
        char * Des;
        char * dpt;
        

     	cptr = new course [NUM];

	fin.open("course.txt");	
	
	
	for(i=0; i <NUM; i++)
	{
	        	fin >>dpt;
	         	(*cptr).setdept(dpt);

		        fin >> kode;
                (*cptr).setcode(kode);

                fin.getline( Des, 50 );
               (*cptr).setclassD(Des);
              	
	}


	cout << " <Schedule> " << endl;
    cout<<endl;


	for(i=0; i<NUM; i++)
    {
 cout << "Course " << ": " <<(*cptr).getdept() << " "<< (*cptr).getcode() << endl;
           cout<<endl;		

          cout<< " class Des " << ":" <<(*cptr).getclassD()<<endl;	
	}	 	
 system("pause");	
     
	return 0;
}

where is the memory allocation for course::classD.
line #32: allocate memory for classD like u did for course::dept

where is the memory allocation for course::classD.
line #32: allocate memory for classD like u did for course::dept

hey thanks for respnding, i have allocate the memory and still the program crahes when I Add the classD thing ...!!! I really dont know what to do ....help please :-) here's the modifications
thanks again

#include <iostream>
#include <stdlib.h>
#include <fstream>
using namespace std;

class course
  {
	public:
     course ();//constructor
    ~course();//destructor 
      
        
	void setdept(char *);
	char * getdept();

	void setcode(int);
	int  getcode();
   
    void setclassD(char * );
    char * getclassD();
    void print() const ;


    private:
            
	char * dept;
	int   code;
    char * classD;
		
 };

course::course()
{
dept = new char [20];
classD = new char [20];

classD[0] = '\0';
dept[0]= '\0';
code = 0;
}

course::~course()
{
delete [] dept;
delete [] classD;
dept = '\0';
code = 0;


}

 void course::setdept(char* dpt)
 { 
 
    dept = new char [20];
	int i = 0;
	while(dpt[i]!='\0')
        {
		dept[i]=dpt[i];
		i++;
	}
	dept[i] = '\0';

 }
 void course::setcode(int kode)
 {
	code = kode;
 }

 char* course::getdept()
 {
	return dept;
 }
int course::getcode()
{	
	return code;
}

void course::setclassD(char * Des)
{

    
    Des = new char [20];
	int i = 0;
	while(Des[i]!='\0')
        {
		classD[i]=Des[i];
		i++;
	}
	classD[i] = '\0';

}

char * course::getclassD()
{

 return classD;
 }

 int main()
  {	
//declaration 
    	ifstream fin;
        int NUM=1; 
        int i;
        int kode;
       	course * cptr;
        char * Des;
    	char * dpt;
        
     	cptr = new course [NUM];
 
 
	fin.open("course.txt");	
	
	
	for(i=0; i <NUM; i++)
	{
	        	fin >>dpt;
	         	(*cptr).setdept(dpt);

		        fin >> kode;
                (*cptr).setcode(kode);

                fin.getline( Des, 50 );
               (*cptr).setclassD(Des);
              	
	}

	cout << " <Schedule> " << endl;
    cout<<endl;

	for(i=0; i<NUM; i++)
    {
		cout << "Course " << ": " <<(*cptr).getdept() << " "<< (*cptr).getcode() << endl;
        cout<<endl;		
        cout<< " class Des " << ":" <<(*cptr).getclassD()<<endl;	
	}	 	
 system("pause");	
     
	return 0;
}


// copy constructors
/* 
course::course(const course &rhs)
{
dept = rhs.dept;
code = rhs.code'
classD = rhs.classD;
 

dept = new char [len+1];
//deep copy 
while (rhs.dept[i] ='\0')
{
strcopy();
}
}
*/
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.