Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 28th, 2005, 12:07 PM   #1
Navid
Hobbyist Programmer
 
Navid's Avatar
 
Join Date: Feb 2005
Location: Canada
Posts: 187
Rep Power: 4 Navid is on a distinguished road
Send a message via MSN to Navid
Flushing out an array (solved)

How can you flush out an array? So it would have no values.

Last edited by navnav; Jun 28th, 2005 at 12:35 PM.
Navid is offline   Reply With Quote
Old Jun 28th, 2005, 12:14 PM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
An array is a series of contiguous memory locations. These are typically little silicon hardware thangies that have their bit storage mechanisms in one state or another: zero (off) or one (on). They never have NO values. They may have unknown values, but values are there. The best you can do is initialize them to some known value which, to YOU, represents nada. A universally useful value for that does not exist since all values are subject to interpretation of one kind or another, depending up their presumed "type".
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Jun 28th, 2005, 12:15 PM   #3
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
You can use the memset() function. Here's a link.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Jun 28th, 2005, 12:18 PM   #4
Navid
Hobbyist Programmer
 
Navid's Avatar
 
Join Date: Feb 2005
Location: Canada
Posts: 187
Rep Power: 4 Navid is on a distinguished road
Send a message via MSN to Navid
nnxion, thanks that worked perfectly

True, but this is a char array im dealing with (should of said that before), so how would it be possible to set it all to 0 without the header <string.h>?
Navid is offline   Reply With Quote
Old Jun 28th, 2005, 12:32 PM   #5
L7Sqr
Hobbyist Programmer
 
Join Date: Jun 2005
Location: here
Posts: 146
Rep Power: 4 L7Sqr is on a distinguished road
int i = 0; 
char val = '\0'; /* here val represents the value you want to assign */
for (;i < length_of_the_array; ++i)
   your_array[i] = val;
That should do what you want (so long as you are able to determine length_of_the_array)
__________________
"...and though our kids are blessed their parents let them shoulder all the blame."
- The Quiet Things That No One Ever Knows [BrandNew]
L7Sqr is offline   Reply With Quote
Old Jun 28th, 2005, 12:35 PM   #6
Navid
Hobbyist Programmer
 
Navid's Avatar
 
Join Date: Feb 2005
Location: Canada
Posts: 187
Rep Power: 4 Navid is on a distinguished road
Send a message via MSN to Navid
OK thanks. Solved
Navid is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 1:40 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC