Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.



This topic is 6652 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi! I''ve got a problem concerning C++ (I''m newbie) I want to create a list: void func1(int *list, int n_elems) { // Here I want to create the list with n_elems elements with // ''new'' list = new int[n_elems]; } void func2(void) { int *list; char c[64]; func1(list, 10); sprintf(c, "%d", list[0]); // Here it crashes } I can''t access the dynamic array I''ve created in func1. There must be something wrong with the pointers. Could someone please help me, I''m really new to C. Thanks in advance cu

Share this post

Link to post
Share on other sites
Your problem is that modifications to the 'list' parameter aren't getting out of 'func1'


1) Change the 'int *list' parameter to '**list' and call func1 like so - 'func1(&list,10)'

2) Change the 'int *list' param to 'int &*list' (or *&list, can't remember which)

3) make your function return the pointer

int *func1(int elems)
return new int[elems];

Or look into the STL, and don't forget 'delete[] list' somewhere



Edited by - Jansic on September 1, 2000 12:41:27 PM

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!