strcpy

This is a discussion on strcpy within the C Programming forums, part of the General Programming Boards category; ....

  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    4

    Exclamation strcpy

    .
    Last edited by Tibo; 03-28-2003 at 02:47 AM.

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Both are valid, assuming you've allocated memory for the pointer (char*). The array is basically a pointer pointing to some statically allocated memory.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Dev
    Dev is offline
    Registered User Dev's Avatar
    Join Date
    Mar 2003
    Posts
    59
    C doesn't check array bounds. So if you just declare as char * or in array fashion like char str[3] that will not do if the string to be copied is of different size.


    So best way is to declare a character pointer. Like char * str;

    and then allocate memory for it using malloc() function.

    But be sure to allocate memory for one more character alongwith number of characters desired to accomodate the null character.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A Full Program to analyze.
    By sergioms in forum C Programming
    Replies: 2
    Last Post: 12-30-2008, 09:42 AM
  2. Strcpy
    By Godders_2k in forum C Programming
    Replies: 17
    Last Post: 12-12-2007, 12:34 PM
  3. Where is strcpy() defined? (Can't find in string.h ect)
    By Zero_Point in forum C++ Programming
    Replies: 6
    Last Post: 04-03-2006, 06:14 PM
  4. Question about strcpy
    By Kevinmun in forum C Programming
    Replies: 4
    Last Post: 11-02-2005, 11:00 PM
  5. strcpy
    By Luigi in forum C++ Programming
    Replies: 17
    Last Post: 02-16-2003, 04:11 PM

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