Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 16-05-2009
Member
 
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.
Reply With Quote
  #2  
Old 16-05-2009
Member
 
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.

Quote:
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.
Reply With Quote
  #3  
Old 16-05-2009
Member
 
Join Date: May 2008
Posts: 2,008
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:-

Quote:
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';
}
Reply With Quote
  #4  
Old 16-05-2009
Member
 
Join Date: Apr 2008
Posts: 2,001
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:
Quote:
memset(test, 0, 10);
Or, you can also try to make it an empty string:
Quote:
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.
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "How do i clear char array in c++"
Thread Thread Starter Forum Replies Last Post
Array of char and int Jensen Ackles Software Development 5 23-03-2010 09:50 AM
Problem in representing 3 x 3 array of char in c++ KAILEY Software Development 5 20-02-2010 08:05 PM
Comparing char array in c++ MAHAH Software Development 5 15-02-2010 08:19 PM
Randomaccessfile using char array TechGate Software Development 5 27-01-2010 11:19 AM
Size of a pointer to an array of char Zool Software Development 3 14-10-2009 12:05 PM


All times are GMT +5.5. The time now is 12:47 AM.