Code Competitions

Coding competition

Wednesday, 12 June 2013

program to copy string to another string without using library function

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
    void read(char *);
    void cpy(char *,char *);
    void display(char *);
    char s[25],*s3;
    clrscr();
    //cout<<" "<<&s3;
    s3=&s[0];
    read(s3);
    cout<<"\nentered string s1 are : ";
    display(s3);
    char p[25],*p4;
    //cout<<" "<<&p4;
    p4=&p[0];
    cpy(s3,p4);
    cout<<"\nafter copy the string s2......\n";
    //s2=s4;
    display(s3);
    getch();
}
void read(char *s)
{
    cout<<"\nenter the string ";
    char i=0;
    while((*(s+i)=getchar())!='\n')
    {
        i++;
    }
    *(s+i)='\0';
}
void display(char *s)
{
    cout<<"\nthe string is ";
    int i=0;
    while((*(s+i))!='\0')
    {
        putchar(*(s+i));
        i++;
    }
}
void cpy(char *s,char *p)
{
    int i=0;
    while(*(s+i)!='\0')
    {
        *(p+i)=*(s+i);
        i++;
    }
    *(p+i)='\0';
}

No comments:

Post a Comment