|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now! |
|
#1
|
||||
|
||||
|
clearing array elements?
I have a character array:
test[10]; slots 0-9 are filled in the array..I want to clear the array so brand new character can be entered in there place. How would I go about doing this? -andy
__________________
hmmm... |
|
#2
|
||||
|
||||
|
Two ways immediately come to mind.
To write over all the elements of the array with a NULL (value of zero), you could either use a loop or use memset: Code:
memset(test, 0, 10); Or, if you just want to make it an empty string: Code:
test[0] = '\0'; In this second case, it doesn't matter that the previous characters are still in the array, because the string ends at the NULL. |
|
#3
|
|||
|
|||
|
third: just enter the new char's in the array. They don't mind if there's a '\0' there or some other char.
Last edited by 7stud : May 10th, 2003 at 02:35 AM. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > clearing array elements? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|