Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Clearing data inside char array.

Status
Not open for further replies.

PrograMan

Programmer
Jul 21, 2001
59
US
I'm looking for a function or something that will empty a char array. I have one in a while loop and unless I am able to empty out the array, the while loop will continue going until something else pauses it. I know that once the array's data is removed, the program will see nothing to work with and thus will stop at the right place and wait for data to be input. Ideas?
 
memset?

/Per
[sub]
"It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure."[/sub]
 
Maybe you can use the memset function.

Code:
 #include <string.h>

 char array[20];
 memset (array, 0, 20 * sizeof (char));//initialize every item of array to zero

--
Globos
 
Sorry for the duplicated answers (PerFnurt is too fast for me today).

--
Globos
 
Heh, but on the other side your explained it a tad bit more :)

/Per
[sub]
&quot;It was a work of art, flawless, sublime. A triumph equaled only by its monumental failure.&quot;[/sub]
 
I think you can clear just like this:

myCharArray[0] = '\0';
or
myCharArray[0] = 0;

Everything comes after 0 will be ignored by standard string processing functions.

Ion Filipski
1c.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top