bharat_r
In the zone
I have my Object Oriented Programming lab exam tomorrow. Hence I'm trying out some programs.
This program is to concatenate Strings using dynamic memory allocation.
I don't get a compiler error but when I run it it doesn't give output.
Please anyone find out the error & tell me asap before tomorrow morning..
thanks
pls help guys..
This program is to concatenate Strings using dynamic memory allocation.
I don't get a compiler error but when I run it it doesn't give output.
Please anyone find out the error & tell me asap before tomorrow morning..
Code:
#include<iostream.h>
#include<string.h>
class stringcon
{
int length;
char *name;
public:
stringcon()
{
length=0;
name=new char[length+1];
}
stringcon(char *s)
{
length=strlen(s);
name=new char[length+1];
}
void display(void)
{
cout<<name<<endl;
}
void join(stringcon &a, stringcon &b)
{
length=a.length+b.length;
delete name;
name=new char[length+1];
strcpy(name,a.name);
strcat(name,b.name);
}
};
int main()
{
stringcon name1("New"),name2("Delhi"),s1;
name1.display();
name2.display();
s1.join(name1,name2);
s1.display();
return 0;
}
thanks
pls help guys..
Last edited: