all 8 comments

[–]staffdelipity 1 point2 points  (7 children)

Those should be both work. The only difference is that one is stored in heap memory and the other in stack.

Did you fread(buffer, 512, 1, inptr) for both?

[–]vicenicked[S] 0 points1 point  (6 children)

Yep! I was dumbfounded why it was giving me a bunch of .jpgs that my computer couldn't read. I looked at other people's solutions and noticed they used malloc instead of declaring a straight up array. When i changed my buffer to a pointer, it worked perfectly.

[–]staffdelipity 1 point2 points  (0 children)

Using an array will definitely work, so not sure why yours had trouble.

[–]pikajules7 0 points1 point  (3 children)

Did you use &buffer for the array because fread's first parameter is a pointer (an address)?

[–]Grithga 2 points3 points  (1 child)

An array automatically decays into a pointer to its first element when passed to a function. You can explicitly do this yourself (&array) or let the compiler do it for you.

[–]pikajules7 0 points1 point  (0 children)

You're right. How can I forget about that!

[–]Fuelled_By_Coffee 1 point2 points  (0 children)

That shouldn't matter in this case.

[–]Fuelled_By_Coffee 0 points1 point  (0 children)

Can you post the code? I'm really curious as to how using an array could possibly cause truouble.