Copy String Without Using Strcpy() Function In C Programming

In this example, we will copy string into another variable without using strcpy() function.

Copy String Without Using strcpy() Function In C Programming

	
#include <stdio.h>
#include <string.h>
    
int main()
{
        char Str[100], CopyStr[100];
        int i;
    
        printf("\n Please Enter any String :  ");
        gets(Str);
    
        for (i = 0; Str[i]!='\0'; i++)
        {
            CopyStr[i] = Str[i];
        }
        CopyStr[i] = '\0';

        printf("\n String that we coped into CopyStr = %s", CopyStr);
        printf("\n Total Number of Characters that we copied = %d\n", i);
        
        return 0;
}
	

Output :

	
Please Enter any String :  Hello World!
String that we coped into CopyStr = Hello World!
Total Number of Characters that we copied = 12
	

Share your thoughts

Ask anything about this examples