Home / Programs / C Program to Copy String Without Using strcpy()
🚀 Programming Example

C Program to Copy String Without Using strcpy()

👁 1,493 Views
💻 Practical Program
📘 Step Learning
C Program to Copy String Without Using strcpy()

💻 Program Code

#include <stdio.h>
int main()
{
    char s1[100], s2[100], i;

    printf("Enter string s1: ");
    scanf("%s",s1);

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

    s2[i] = '\0';
    printf("String s2: %s", s2);

    return 0;
}
                        

🖥 Program Output

Enter String s1: atnyla
String s2: atnyla
                            

📘 Explanation

You can use the strcpy() function to copy the content of one string to another but, this program copies the content of one string to another manually without using strcpy()function.

This above program copies the content of string s1 to string s2 manually.

📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.