-->

WAP to copy a string without using strcpy().

in turboc++
---------------------------------------------------------------------------------------------------------
//WAP to copy  a string  without using(strcpy()) function.
#include <stdio.h>
#include<string.h>
#include<conio.h>
int main()
{
    char st[100],st1[100];//two string declaration
    int i;
    printf("enter first string\n");
    //fgets(name, sizeof (name), stdin);//to input string with space
    scanf("%[^\n]s",st); //it also CAN BE USED. IT accepts string with space until it meets new line
    for(i=0;st[i]!='\0';i++)//loop execution till
    {
        st1[i]=st[i];//copying characters
    }

    st1[i]='\0';//adds an extra null character at the end.

       printf("copied string =%s\n",st1);//prints the name in lowercase
     getch();
    return 0;
}

------------------------------------------------------------------------------------------------------
in codeblocks
------------------------------------------------------------------------
//WAP to copy  a string  without using(strcpy()) function.
#include <stdio.h>
#include<string.h>
int main()
{
    char st[100],st1[100];//two string declaration
    int i;
    printf("enter first string\n");
    //fgets(name, sizeof (name), stdin);//to input string with space
    scanf("%[^\n]s",st); //it also CAN BE USED. IT accepts string with space until it meets new line
    for(i=0;st[i]!='\0';i++)//loop execution till
    {
        st1[i]=st[i];//copying characters
    }

    st1[i]='\0';//adds an extra null character at the end.

       printf("copied string =%s\n",st1);//prints the name in lowercase
    return 0;
}


No comments:

Post a Comment