Sign in to follow this  
Sabonis

allocating memory for arrays

Recommended Posts

hey guys, I'm writing a program in C that will fill in an allocated array of doubles... My question is: What is the right way to allocate memory for an array of doubles with malloc()? double *input; input = (double*)malloc(sizeof(double)*num_elements); is what i have so far... doesnt seem to work. Any ideas?

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
What do you mean by "doesn't seem to work"?


... as in when I try to access the elements my program crashes

Share this post


Link to post
Share on other sites
Is the return value from malloc() 0? If so you might have heap corruption somewhere else in your program, or num_elements could be too big.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this