-----------------------------------------------------------------------------------------------------------------------
Author: Sujith
Program: Write C++ programs to concatenate two string without using inbuilt functions
Prog Name: 1strcat.cpp
Date: 21-04-2015
--------------------------------------------------------------------------------------------------------------------------
#include<iostream>
using namespace std;
void fnStrJoin(char s1[30],char s2[30]);
main()
{
char str1[30],str2[30];
system("clear");
cout<<"Enter 1st string\n";
cin>>str1;
cout<<"Enter the second string\n";
cin>>str2;
fnStrJoin(str1,str2);
cout<<"New String:"<<str1<<"\n";;
}
void fnStrJoin(char s1[30],char s2[30])
{
int i,j=0;
for(i=0;s1[i]!='\0';i++);
while(s2[j]!='\0'){
s1[i]=s2[j];
i++;
j++;
}
s1[i]='\0';
}
OUTPUT:
"1strcat.cpp" 28L, 567C written
[141740@localhost ~]$ g++ 1strcat.cpp
[141740@localhost ~]$ ./a.out
Enter 1st string
Kerala
Enter the second string
Strikers
New String:KeralaStrikers
[141740@localhost ~]$
Author: Sujith
Program: Write C++ programs to concatenate two string without using inbuilt functions
Prog Name: 1strcat.cpp
Date: 21-04-2015
--------------------------------------------------------------------------------------------------------------------------
#include<iostream>
using namespace std;
void fnStrJoin(char s1[30],char s2[30]);
main()
{
char str1[30],str2[30];
system("clear");
cout<<"Enter 1st string\n";
cin>>str1;
cout<<"Enter the second string\n";
cin>>str2;
fnStrJoin(str1,str2);
cout<<"New String:"<<str1<<"\n";;
}
void fnStrJoin(char s1[30],char s2[30])
{
int i,j=0;
for(i=0;s1[i]!='\0';i++);
while(s2[j]!='\0'){
s1[i]=s2[j];
i++;
j++;
}
s1[i]='\0';
}
OUTPUT:
"1strcat.cpp" 28L, 567C written
[141740@localhost ~]$ g++ 1strcat.cpp
[141740@localhost ~]$ ./a.out
Enter 1st string
Kerala
Enter the second string
Strikers
New String:KeralaStrikers
[141740@localhost ~]$
No comments:
Post a Comment