C++ help...

RGN

Diamond Member
Feb 24, 2000
6,623
6
81
How do I clear and array after I read the data?

The data is being read in a for loop.

I tried using this:

delete [] array_name;

but my program crashes.


Ideas?
 

Deeko

Lifer
Jun 16, 2000
30,213
12
81
That is for a dynamic array.

example:

int *array = new int[5];

cout << array[whatever u wanna do];

delete array [];
 

Deeko

Lifer
Jun 16, 2000
30,213
12
81
easy....make it dynamic :) What do want it to do, actually delete the memory space, or just like reset the values to 0 or something? If you want to just delete the memory space, I don't know if it's possible.
 

RGN

Diamond Member
Feb 24, 2000
6,623
6
81
This is a base conversion program, the values that are input in the array are being read out along with new data on subsequent calculations.

example:

first answer is 444, second answer displayes as:4446767

it should be 6767

I'm not sure going to zero's is what I'm looking for...
 

Deeko

Lifer
Jun 16, 2000
30,213
12
81
Hmm...not really sure what you're trying to do, but if you just need to delete the whole thing, just make the array dynamic.
 

FatAlbo

Golden Member
May 11, 2000
1,423
0
0
Keep track of how many elements you're using for each conversion, and use a loop to display however many elements you've counted.
 

RGN

Diamond Member
Feb 24, 2000
6,623
6
81
I GOT IT!!!


FatAlbo:I was keeping track, but I was not resetting my counter.


Thanks!!
 

MC

Platinum Member
Feb 23, 2000
2,747
0
0
not sure whether your problem is solved or not.

if i were you i will just replace the Array's content next time you store date to it. :)