How to write a C Program low level strcpy in C Programming Language ?
This C Program low level strcpy. Wipe the string first
-This is so that you don't end up with "Hello" mutating to something like "Hello5" if dest is e.g. "098765".
Solution:
- void copy_string(char *src, char *dest){
- char *ps = src,
- *pd = dest;
- /* Wipe the string first
- * This is so that you don't end up with "Hello" mutating to
- * something like "Hello5" if dest is e.g. "098765"
- */
- while(*pd){
- *pd = 0;
- pd++;
- }
- /* Reset pd */
- pd = dest;
- /* Finally, copy our source */
- while(*ps){
- *pd = *ps;
- pd++;
- ps++;
- }
- }