Results 1 to 4 of 4

Thread: How do i clear char array in c++

  1. #1
    Join Date
    Apr 2009
    Posts
    102

    How do i clear char array in c++

    Can any body tell me that which is the most effecitive way to clear a clear a char array in c++? I would like to know the most effective way that i can used in c++ in order to clear char array. Does any body knows about it? Kindly provide me the correct information on the above issue. Any kind of help on the above issue would be appreciated.

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: How do i clear char array in c++

    The quickest way to clear an array is as follows.

    struct Row
    {
    int count;
    char entries[10000];
    };

    struct Page
    {
    int count;
    Row entries[400];
    };
    Now, it will depend om how you will populate the data, for that you first have to set the appropriate count to 0, then you need to fill in the equired elements into entries, then try to set the count to a particular number of elements that you add.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: How do i clear char array in c++

    Inorder to clear the char array, you need to hold the strings and assign the null char to index 0.

    Noue:- '\0', \0, and 0 are all ways of indicating null char.

    You need to put a null char in each index zero and you just need to loop the array in the following ways:-

    char 2Darray[10][7];
    for (int ct = 0; ct < 10; ct++) /*note that you need to give ct some starting value before it's used in the loop*/
    {
    2Darray[ct][0] = '\0';
    }

  4. #4
    Join Date
    Apr 2008
    Posts
    2,005

    Re: How do i clear char array in c++

    There are two ways by which yoou can clear the char array in c++

    In order to over write the elements of the array with a NULL (value of zero), you could either use a loop or use memset:
    memset(test, 0, 10);
    Or, you can also try to make it an empty string:
    test[0] = '\0';
    In the second phase, it doesn't matter if the previous characters are still in the array, because the string ends are set at the NULL.

Similar Threads

  1. Array of char and int
    By Jensen Ackles in forum Software Development
    Replies: 5
    Last Post: 23-03-2010, 09:50 AM
  2. Problem in representing 3 x 3 array of char in c++
    By KAILEY in forum Software Development
    Replies: 5
    Last Post: 20-02-2010, 08:05 PM
  3. Comparing char array in c++
    By MAHAH in forum Software Development
    Replies: 5
    Last Post: 15-02-2010, 08:19 PM
  4. Randomaccessfile using char array
    By TechGate in forum Software Development
    Replies: 5
    Last Post: 27-01-2010, 11:19 AM
  5. Size of a pointer to an array of char
    By Zool in forum Software Development
    Replies: 3
    Last Post: 14-10-2009, 12:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,499,711.60814 seconds with 17 queries