Jax-p
Jax-p

Reputation: 8531

How to use value from dynamic array

I have dynamicly allocated array (via malloc) of numbers (called "double** metrix") and I need to get the right values and send them to the other function.

I can print the value rightly by using printf("%d", metrix[1][1]) but when I try something like double number; number = metrix[1][1] I get random number (probably randomly selected part of memory?).

How to use this right to get the value I need? Thank you for any help and sorry for my english.

Upvotes: 0

Views: 67

Answers (2)

steffen
steffen

Reputation: 8958

%d stands for decimal integer, not double. What you want is %f which means (fixed) floating point

Upvotes: 0

Viet
Viet

Reputation: 583

If you use malloc function, it only allocates a block of size bytes of memory, but the content of the newly allocated block of memory is not initialized, remaining with indeterminate values.

And if you want to print a double value, please use "%f" instead "%d"

Upvotes: 1

Related Questions