basic question to Arrays

This is a discussion on basic question to Arrays within the C++ Programming forums, part of the General Programming Boards category; Hi I have a basic question to the use of Arrays (I have been searching the net for the answer ...

  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.
    Im 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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,484
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 02: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, 08:59 AM
  5. Question on Arrays
    By shin in forum C Programming
    Replies: 10
    Last Post: 06-06-2004, 01:11 PM

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