Thread: Array question

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    Registered User
    Join Date
    Apr 2003
    Posts
    2,663
    Since you are using a simple array, you had to declare its size in your program, so you already know the size of the array, and you should use that in your loop. For instance:
    Code:
    const int size = 10;
    char myArray[size] = "hello";
    ...
    ...
    for(int i=0; i<size; i++)
    {
    }
    Also, as was mentioned, you might not need to erase the array because you can do this:
    Code:
    char myArray[10] = "hello";
    strcpy(myArray, "hi");
    cout<<myArray<<endl;
    If you were using string types, you could do this:
    Code:
    string myStr = "hello world";
    myStr = "";
    Last edited by 7stud; 02-22-2006 at 11:20 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Dynamic Mutli dimensional Array question.
    By fatdunky in forum C Programming
    Replies: 6
    Last Post: 02-22-2006, 07:07 PM
  2. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM
  3. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 09:54 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. array question?
    By correlcj in forum C++ Programming
    Replies: 1
    Last Post: 11-08-2002, 06:27 PM