Character Array copying

This is a discussion on Character Array copying within the C Programming forums, part of the General Programming Boards category; Hi, Many thanks to hk_mp5kpdw for answering my previous post, was perfect thanks! Since this is a different problem I ...

  1. #1
    Registered User
    Join Date
    Mar 2005
    Posts
    24

    Character Array copying

    Hi,

    Many thanks to hk_mp5kpdw for answering my previous post, was perfect thanks!

    Since this is a different problem I figured a different topic would be wise, this time it should be fairly simple. Ive simply forgotten how to make one character array equal to another
    eg

    Code:
    char name[20];
    char tname[20];
    
    tname = name;
    I need tname to become equal to name as I am passing it to another function, but I cant find the lecture we had on this.

    Thanks
    -Steve

    Edit- sorry, I have a scanf to take a value for name before I reach tname = name and tname should be empty.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    strcpy()

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    24
    thats the one

    Cheers

  4. #4
    Registered User coolshyam's Avatar
    Join Date
    Mar 2005
    Posts
    26

    Cool two methods

    hi there
    you can use two methods for this
    1. as our dear friend notified, use
    Code:
    strcpy(tname,name);
    else
    Code:
        int i;
        for(i=0;i<20;i++)
        {
                 tname[i]=name[i];
         }

    any questions any type in programming

    a ready made answer
    -----------------------------------------------------------------------------------
    FORTUNE FAVOURS THE BOLD!
    -----------------------------------------------------------------------------------

  5. #5
    Registered User
    Join Date
    Jan 2005
    Posts
    847
    And there is also memcpy...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Converting character array to integer array
    By quiet_forever in forum C++ Programming
    Replies: 5
    Last Post: 04-02-2007, 06:48 AM
  2. question about multidimensional arrays
    By richdb in forum C Programming
    Replies: 22
    Last Post: 02-26-2006, 09:51 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02:53 AM
  4. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 05:15 AM
  5. Character Array - almost? works
    By voltson4 in forum C Programming
    Replies: 3
    Last Post: 03-04-2003, 06:03 PM

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