i need to know a simple program to concat two strings without using strcat inside operator overloading.plz help me with a program..............
C++????????
The program above is close, but the way it is written, you are going to write over whatever is in memory following the q string.
It also is destructive of the input string q since it uses it to compute the concatination.
char* ConcatStrings(char *p, char *q)
{
int size = 0;
char* s = p;
while (*s)
{
size++;
s++;
}
char* s = q;
while (*s)
{
size++;
s++;
}
char* retValue = new char[size+1];
s = retValue;
while(*p)
{
*s++ = *p++;
}
while(*q)
{
*s++ = *q++;
}
*s = '\0';
return retValue;
}
Don't forget that you are responsible for the memory allocated for the new string. Delete it when you are done with it.
Reply:#include%26lt;stdio.h%26gt;
#include%26lt;conio.h%26gt;
void main(){
char *dest="kamuri";
char *src="3636";
const char *p;
char *q;
for(q=dest;*q!='\0';q++);
for(p=src;*p!='\0';p++,q++)
*q=*p;
*q='\0';
printf("%s", dest);
getch();
}
Reply:do u mean whith the can thing or something totally diferent
Reply:idk but thats the grade i got in my english class lol
Reply:Just store 2 strings in array, and define 3rd big array, then just coccatenate it using loop.
Reply:hey . plz ask sum experts otherwise u will get confused
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment