Thread: basic question to Arrays

  1. #1
    Registered User
    Join Date
    Dec 2004
    Posts
    4

    basic question to Arrays

    Hi
    I have a basic question to the use of Arrays (I have been searching the net for the answer without success, so now I try here...)

    Somewhere in my code I declare two arrays:


    char TagID[16];
    ....
    char tempID[16];


    Then I want to copy the CONTENT of the 2nd array into the 1st one.
    I´m not sure, but I believe that
    TagID=tempID;
    will just make tempID refer to the same array as TagID,without copying the content.

    Is there any predefined method I can use?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well for strings (char arrays containing a \0 to mark the end of the string), you use the strcpy() call.
    For arrays of any other type, use memcpy() or a loop to copy each index yourself
    for ( i = 0 ; i < N ; i++ ) b[i] = a[i];
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Very quick question about dynamic arrays.
    By Lawn Gnomusrex in forum C++ Programming
    Replies: 4
    Last Post: 11-13-2008, 03:22 PM
  2. Function name basic question help
    By kenryuakuma in forum C++ Programming
    Replies: 7
    Last Post: 09-24-2008, 07:48 AM
  3. Replies: 9
    Last Post: 06-09-2008, 09:53 AM
  4. Visual Basic Question
    By Xeavor in forum Tech Board
    Replies: 5
    Last Post: 12-02-2004, 09:59 AM
  5. Question on Arrays
    By shin in forum C Programming
    Replies: 10
    Last Post: 06-06-2004, 01:11 PM