Write your own definition of strcpy using array notation Th
Write your own definition of strcpy( ) using array notation. (This means write the code that implements the function. Refer to Appendix B for the strcpy( ) function prototype.)
Solution
The C programming language offers a libary function called strcpy, defined in the string.h header file, that allows null-terminated memory blocks to be copied from one location to another. Since strings in C are not first-class data types and are implemented instead as contiguous blocks of bytes in memory, strcpy will effectively copy string given two pointers to blocks of allocated memory.
prototype function :
char * strcpy( char * destination, const char *source) ;
The strcpy function performs a copy by iterating over the individual character of thr string and copying them one by one. An explicit implementation of strcpy is :
char *strcpy(char *dest, const char *src)
{
unsigned i;
for (i=0; src[i] !=\'\\0\'; ++i)
dest[i] = src[i];
dest = \'\\0\' ;
return dest ;
}
A common implementation is :
char *strcpy (char 8dest, const char *src)
{
char *save = dest ;
while (*dest++ = *src++0;
return save ;
}
