Copying string without library function || String || C programming
In this, we are going to see a program to copy string without using strcpy() with help of C Programming Language.


#include <stdio.h>

int main()
{
    //two character arrays s1,s2
    char s1[100], s2[100], i;

    printf("Enter string s1:\n");
    // Read string from stdin, of maximum length 100
    fgets(s1, 100, stdin);

    for (i = 0; s1[i] != '\0'; ++i) // copy to s2
    {
        s2[i] = s1[i];
    }

    // Append NULL character at end to mark end of string
    s2[i] = '\0';
    printf("String s2: %s", s2);

    return 0;
}

//........coded by ANANYA MAURYA

#ENJOY CODING


Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post