#Deleting the contents of an array

32 messages · Page 1 of 1 (latest)

unreal moatBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

foggy leaf
#

int arr[] = {};kekw

silent hill
vestal folio
#

Delete them as in set them all to zero?

silent hill
#

basically i want it to have no value

#

just like when u declare it

vestal folio
#

I don’t think you can uninitialize memory. Best you could maybe do is free the array if it’s allocated on the heap

#

Why are you trying to do this anyways?

silent hill
#

I'm creating snake in C, I have to draw on the screen the table where the snake and the food are located; to do this I check the Y coordinate of each single piece of the snake/food and if it corresponds to the number of the line I am drawing I write its X in that array to then know where to draw it on that line

#

the problem is that since i cant delete the contents of the array i always draw everything in the same X

silent hill
vestal folio
#

Couldn’t you overwrite all the previous value in the array for your next draw cycle?

silent hill
#

yeah imma try it

#

maybe il set every value to something like 99 and not draw anything if its equal to if

vestal folio
#

Why would you do that when you can overwrite the old values? Pass a length variable around too so you don’t go past what x values you wrote in that cycle

#

Also why can’t you go directly from an x and y to a point drawn on the screen? Wouldn’t that make this algorithm much more efficient and avoid this array stuff?

silent hill
#

i prob fucked up

silent hill
#

im making some progress rn, i think i can finish this in a couple of days

foggy leaf
#

memset to zero?

vestal folio
#

He doesn’t want it to just be zero

silent hill
#

like if a make an array : numbers[2] but then i want to put 3 numbers there

arctic crater
silent hill
#

i think i may have found the problem

#

i had some nested for loops and i wrote [j] instead of [i] for an array

#

if that isnt whats worng im switching to something else cuz its making me wanna trow my pc out of the window

arctic crater
#

I, nor anyone else, know exactly what you are doing and what errors you are facing since you didn't include your code (the relevant part of it) in the post bing_shrug

silent hill
#

also the comments and variable names arent in english so it would probably be hard to understand

arctic crater
# silent hill idk how to🥲 cuz its too long

Break it down to bits: specify what you think is going wrong in your code, what was your intention behind asking your original question, find where you think your problem is, or where it's likely to be at and include it here.

#

Seems like a XY problem.

silent hill
#

yes