Code Competitions

Coding competition

Friday, 31 May 2013

program to concatenate 2 string using pointers

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void main()
{
    char *s1,*s2,*t1,*t2;
    void display(char *);
    void cat(char *,char *);
    s1=t1;
    s2=t2;
    clrscr();
    cout<<"\nenter the 1st string ";
    gets(s1);
    cout<<"\nenter the 2nd string ";
    gets(s2);
    cout<<"\n my first string was ";
    display(s1);
    cout<<"\n my 2nd string was ";
    display(s2);
    s1=t1;
    s2=t2;
    cat(s1,s2);
    cout<<"\n my final string was ";
    display(s1);
    getch();
}
void display(char *a)
{
    while(*a!='\0')
    {
        cout<<*a;
        a++;
    }
}
void cat(char *d,char *s0)
{
    while(*d!='\0')
    {
        d++;
    }
    while(*s0!='\0')
    {
        *d=*s0;
        d++;
        s0++;
    }
    *d='\0';
}

No comments:

Post a Comment