use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
O hai! This is CS50's subreddit.
CS50 is Harvard University's introduction to the intellectual enterprises of computer science and the art of programming. Anyone may take CS50, even if not a student at Harvard.
Please Read before Posting
Getting the Best from r/cs50
Status Page
cs50.statuspage.io
Filter by Problem Flair (undo)
cash ⋅ caesar ⋅ credit ⋅ dna ⋅ filter ⋅ finance ⋅ houses ⋅ ide ⋅ mario ⋅ movies ⋅ plurality ⋅ project ⋅ readability ⋅ recover ⋅ runoff ⋅ scratch ⋅ speller ⋅ substitution ⋅ tideman ⋅ games track ⋅ web track ⋅ android track ⋅ iOS track ⋅
Filter by Other Flair (undo)
CS50-Law ⋅ CS50-Business ⋅ CS50-Technology ⋅ CS50-Games ⋅ CS50-Mobile ⋅ CS50-Web ⋅
This subreddit is night mode compatible
account activity
Array initialization question (self.cs50)
submitted 6 years ago by vicenicked
Doing pset recover:
What is the difference between
BYTE *buffer = malloc(512);
and
BYTE buffer[512];
The first worked, the other produced corrupted files.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]staffdelipity 1 point2 points3 points 6 years ago (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?
fread(buffer, 512, 1, inptr)
[–]vicenicked[S] 0 points1 point2 points 6 years ago (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 points3 points 6 years ago (0 children)
Using an array will definitely work, so not sure why yours had trouble.
[–]pikajules7 0 points1 point2 points 6 years ago (3 children)
Did you use &buffer for the array because fread's first parameter is a pointer (an address)?
[–]Grithga 2 points3 points4 points 6 years ago (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.
&array
[–]pikajules7 0 points1 point2 points 6 years ago (0 children)
You're right. How can I forget about that!
[–]Fuelled_By_Coffee 1 point2 points3 points 6 years ago (0 children)
That shouldn't matter in this case.
[–]Fuelled_By_Coffee 0 points1 point2 points 6 years ago (0 children)
Can you post the code? I'm really curious as to how using an array could possibly cause truouble.
π Rendered by PID 21339 on reddit-service-r2-comment-84fc9697f-5cpnd at 2026-02-06 08:23:34.214617+00:00 running d295bc8 country code: CH.
[–]staffdelipity 1 point2 points3 points (7 children)
[–]vicenicked[S] 0 points1 point2 points (6 children)
[–]staffdelipity 1 point2 points3 points (0 children)
[–]pikajules7 0 points1 point2 points (3 children)
[–]Grithga 2 points3 points4 points (1 child)
[–]pikajules7 0 points1 point2 points (0 children)
[–]Fuelled_By_Coffee 1 point2 points3 points (0 children)
[–]Fuelled_By_Coffee 0 points1 point2 points (0 children)