Monday, January 31, 2011

Arrays in C++

Concatenation  of two string arrays.
If this program make any errors please let me know,i will try to help you out.

# include <iostream>
# include <conio.h>
#include<string.h>
using namespace std;
void mystringconc(char [],char []);
main()
{
char a[30],b[30];
int i,j;
i=j=0;
cout<<"Enter the first name:";
gets(a);
cout<<"Enter the second name:"<<endl;
gets(b);
mystringconc(a,b);
getch();
return 0;
}
void mystringconc(char a[],char b[])
{
     int i,j;
     char c[60];
     i=j=0;
while(a[i]!='\0')
{
c[i]=a[i];
i++;
}
c[i]='\0';
while(b[j]!='\0')
{
    c[i]=b[j];
    j++;
    i++;
}
c[i]='\0';
cout<<"your first name is:"<<a<<endl;
cout<<"Your second name is:"<<b<<endl;
cout<<"your full name is :"<<c;                 
}

No comments:

Post a Comment