mem copy help need

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • askcq
    New Member
    • Mar 2007
    • 63

    mem copy help need

    Code:
    main()
    {
    char *sou;
    char *dest;
    char str[4]={"ie"};
    char str1[4]={"ee"};
    int size;
    dest=&str;
    sou=&str1;
    printf("%s\n",sou);
    printf("%s\n",dest);
     size =strlen(str);
    printf("%dsize\n",size);
    memcpy(dest,sou, size);
    
    printf("%s",*sou);
    printf("\n%s",*dest);
    
    }
    i couldnt copy the strings...pls help
    Last edited by horace1; Apr 2 '07, 08:36 AM. Reason: added code tags
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    sou and dest are char* so you don't need the * to dereference them in the printf statement
    Code:
    printf("%s",*sou);
    printf("\n%s",*dest);
    also strlen() returns the number of characters in the string not counting the terminating null so you need to add 1 to size, e.g.
    Code:
     size =strlen(str)+1;
    printf("%dsize\n",size);
    memcpy(dest,sou, size);
    printf("%s",sou);
    printf("\n%s",dest);

    Comment

    Working...