471,831 Members | 1,294 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,831 software developers and data experts.

Code for Concatenation and substr

hi freinds,
I want the code for string concatenation and string substr without using the strcat and substr functions...
What could be C++ code for this?
Sep 21 '06 #1
3 4055
Please reply it as early as possible if anybody knows it
Sep 21 '06 #2
Why don't you give a try??

concatenation............

your should be same as the prototype of strcat()

char *xstrcat(char *str1, char *str2)

move the pointer forward unless it points to a null character, i.e., access all the elements of the first string by the pointer str1. Then acceess each element of second string to the first. At last add a null character.


Provide the prototype for the function substr().
Sep 21 '06 #3
void concat()
{
char str1[29];
char str2[29];
char str3[29];
for(p=0;p<5;p++)
{
cout<<"Enter string1;
cin>> str1[p];
}
for(q=0;q<5;q++)
{
cout<<"Enter string2;
cin>> str2[q];
}
for(int i=0,j=0;str1[i]!='\0';i++,j++)
str3[i++]=str1[j++];

for(int k=0;str2[k]!='\0';k++,i++)
str3[i++]=str2[k++];
str3[k]='\0';
cout<<str3;

}
This is waht i tried for concatenation..but its not working..there is some error when i am taking the input into the strings str1 and str2...i am not able to read the input properly into the strings..how to read the input properly>???
Sep 21 '06 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

5 posts views Thread by MuffinMan | last post: by
3 posts views Thread by Craft | last post: by
5 posts views Thread by Jonas Galvez | last post: by
1 post views Thread by Jim Dawson | last post: by
18 posts views Thread by Larry Menard | last post: by
reply views Thread by Lildog | last post: by
6 posts views Thread by sks | last post: by
5 posts views Thread by jgentes | last post: by
NeoPa
reply views Thread by NeoPa | last post: by
aboka
reply views Thread by aboka | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.