Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Write a function that copies a string into another.

+4 votes
asked Oct 21, 2021 by Jamal Abdul-Gafar Abiola (160 points)

How do I Write a function that copies a string into another. The destination string will already have enough memory to copy the source string.
It must work the same way as strcpy(3)

It must be prototyped as follows:

char *my_strcpy(char *dest, const char *src);

The function returns dest.

1 Answer

+2 votes
answered Oct 22, 2021 by Peter Minarik (86,720 points)
edited Oct 22, 2021 by Peter Minarik

You have to consider what a C string is: a sequence of characters ending with a terminating-zero character ('\0').

So copying it from the source to the destination is as simple as copying all the characters one by one from the beginning of the source until the terminating-zero character is found (it should be copied as well).

Based on this, you should be able to write the implementation. When ready, post it for a review. ;)

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...