Search This Blog

Saturday, 4 May 2019

C Program to Copy String Without Using strcpy()

WELCOME BACK TO , In this article, you'll learn to copy string without using the library function strcpy().

To understand this example, you should have the knowledge of following C programming topics:

C Programming Arrays
C Programming Strings
C Programming for Loop

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.

Example: Copy String Manually Without Using strcpy()


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

    printf("Enter string s1: ");

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

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

    return 0;


No comments:

Post a Comment