Home / Programs / Write a program that uses a function to copy one string into another without using the strcpy() function available in the standard library of C.
🚀 Programming Example

Write a program that uses a function to copy one string into another without using the strcpy() function available in the standard library of C.

👁 889 Views
💻 Practical Program
📘 Step Learning
Write a program that uses a function to copy one string into another without using the strcpy() function available in the standard library of C.

💻 Program Code

 #include <stdio.h>
void string_copy(char [], char []); /* function prototype */


int main()
{
	char a[100]; /*** source string ***/
	char b[100]; /*** destination string ***/
	printf("\n Input source string : ");
	scanf("%[^\n]",a); /* read input source string */
	string_copy(b,a); /* function call */
	printf("\n Destination string : %s\n",b);
	return 0;
}
/*** function definition ***/
void string_copy(char d[], char s[])
{
	int i = 0;
	printf("\n Source string : %s\n",s);
	/* copying the string */
	for (i = 0; s[i] != '\0'; i++)
			d[i] = s[i];
	d[i] = s[i]; /* Copy NUL character to destination string */
}
 
                        

🖥 Program Output

 Input source string : atnyla

 Source string : atnyla

 Destination string : atnyla

 
                            

📘 Explanation

None
📚 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.