strcpy syntax explanation needed

This is a discussion on strcpy syntax explanation needed within the C++ Programming forums, part of the General Programming Boards category; hi, can someone explain the following (or better, point me someplace that could explain common command syntax questions). "str" "s" ...

  1. #1
    Registered User blight2c's Avatar
    Join Date
    Mar 2002
    Posts
    266

    strcpy syntax explanation needed

    hi, can someone explain the following (or better, point me someplace that could explain common command syntax questions). "str" "s" are private char. thanks.

    Code:
    strcpy(str,s);

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    strcpy ( str, s );

    This function will take the value of s and place it in str, assuming that there is space allocated for str. The first argument to strcpy is a char * and the second is a const char *. So you can only place s in str if str is a char array or dynamically allocated char *.

    -Prelude
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    1,595
    also, str has to have enough memory to hold the entire string being copied into it, not just some memory.

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >str has to have enough memory to hold the entire string being copied into it
    This goes without saying of course, it's only common sense to see that if you are putting stuff in a box there has to be enough room in the box.

    I don't immediately assume that someone is completely stupid, they have to earn that right.

    -Prelude
    My best code is written with the delete key.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  2. Learning OpenGL
    By HQSneaker in forum C++ Programming
    Replies: 7
    Last Post: 08-06-2004, 08:57 AM
  3. Explanation of a Compilation Error Needed
    By Zildjian in forum C Programming
    Replies: 2
    Last Post: 10-23-2003, 02:04 AM
  4. Replies: 6
    Last Post: 04-04-2003, 09:09 PM
  5. Explanation needed, what is this?
    By CAP in forum C Programming
    Replies: 8
    Last Post: 06-25-2002, 04:07 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21