#Dynamic memory, Realloc in question,
1 messages · Page 1 of 1 (latest)
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 run !howto ask.
just ping me if you reply ^^
Just paste the relevant parts where at least all the variables are defined.
wdym? sorry for late response btw
@keen quest Didn't understand your question clearly
ok so uh
basically arr is a pointer
that is already allocated
and i want to ADD more slots to it
so uhm
when i do something like that
size is known and part is input btw!
so say my length is 3, and i enter 2, it makes my array length 2 somehow
No, that is not right, because, if you enter 2, then your size will be 3+2 =5
@keen quest
Ok so now i got your question @keen quest
yeah, my bad. i didnt word it correctly
You want to make the array length equal to the inpt
like this
Ok got it, it should be total of both, but it is 2 instead of 5
But how did you know that it has became 2 and not 5?
@keen quest Can you show me where you have declared and defined size variable?
uhh
wait
its basically
i have a list of functions to make
uhh
wait
one of them is print values
basically
and just i see all the values get removed
so its easy to tell
@ripe holly
@keen quest Ohk
so uhm, what can i do about it?
@keen quest Possible reason is, value of size can be 0 due to some reason, print size before you reallocate the memory and check if size is 0 or not
@keen quest Also, i didn't get that how did you know that it has became 2 instead of 5?
because
i have a command that prints all values
meaning i see 5 values, after the change i get only 2 values
Do you always print the values from the most recent return value of realloc?
Remember that realloc isn't guaranteed to return the same pointer value you give it.
This question is being automatically marked as stale.
If your question has been answered, run !solved.
If your question is not answered feel free to bump the post or re-ask.
Take a look at !howto ask for tips on improving your question.
then to fix the issue, should i just make a second array to store all values? then after every realloc i just say arr = arr2 or smt