Thread: pointer help

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    32

    pointer help

    Code:
    void strcpy(char *s, char *t)  {  while ( (*s++ = *t++) != '\0');}
    If s is source string means it works correctly but actually I try to copy the t content into s.if t is source means it will coped two times so i could not understood this pointer....OMG...


    Thank you...

  2. #2
    Registered User dariyoosh's Avatar
    Join Date
    Nov 2012
    Location
    Iran / France
    Posts
    38
    What is exactly the problem? there is a source string and a target string, it is up to the user to define the effective parameters properly while calling the function.


    Regards,
    Dariyoosh
    Last edited by dariyoosh; 11-24-2012 at 03:06 PM.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    Quote Originally Posted by amzc View Post
    If s is source string means it works correctly but actually I try to copy the t content into s.if t is source means it will coped two times ...
    The line
    Code:
     while ( (*s++ = *t++) != '\0');
    copies t to s until a null character is encountered in s. Notice this is the same as:
    Code:
    dest = source;
    This means the value of source will be copied into dest. Intuitively speaking, the information moves from the right-hand side of the equals sign to the left-hand side. For this reason it is convient to define the strcpy arguments similarly:

    strcpy(dest, source);

    Of course, for your own functions you're free to use whatever convention is most convenient.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 06-27-2012, 07:05 AM
  2. Replies: 3
    Last Post: 10-30-2009, 04:41 PM
  3. Replies: 9
    Last Post: 06-13-2009, 02:31 AM
  4. Replies: 1
    Last Post: 03-24-2008, 10:16 AM
  5. Replies: 4
    Last Post: 08-27-2007, 11:51 PM