The Open Source Swiss Army Knife

/code/cPP/basics_cPP/
/code/cPP/basics_cPP/ + sub-categories
http://www.sirfsup.com/
web directory content
    
      

Not logged in
Chat Register Login
return to:  http:/www.sirfsup.com      /code   /cPP   /basics_cPP 
Permalink: strcpy2.c
Title: copy one string into another with this function
article options : please login   |  raw source view  

#include<stdio.h>
/*  Again, the function is designed to accept the values of two character
  pointers, i.e. addresses */
main (int argc, char *argv[]) {
  char strA[80] = "A string to beused for demonstration only.";
  char strB[80];

  char *my_strcpy(char *destination, char *source) {
    char *p = destination;
    while (*source != '\0') {
      *p++ = *source++;
    }
    *p = '\0';
    return destination;
  }

   my_strcpy(strB, strA);

   puts(strB);
}

/*  
I have deviated slightly from the form used in standard C which
would have the prototype: 

    char *my_strcpy(char *destination, const char *source);  

Here the "const" modifier is used to assure the user
that the function will not modify the contents pointed to by the
source pointer. 
*/

Leave a Reply
Your Name:     anonymous
Your Email:
Website:  
Comments:

The author will be notified of your reply.
return to top