dynamic memory allocation

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Apr 2007
Posts: 3
Reputation: negbballer54 is an unknown quantity at this point 
Solved Threads: 0
negbballer54 negbballer54 is offline Offline
Newbie Poster

dynamic memory allocation

 
0
  #1
Apr 2nd, 2007
Hey, I'm writting a program in C that is supposed to be a simple connect four game. I ran into problems when I tried to assign my array connects to a set value. The compiler gave me the error, Invalid indirection. Heres a little bit of the code where the problem is.

  1. // ask user how big of a board is wanted
  2. printf("\n\nSelect game board size.");
  3. printf("\nEnter number of rows. (min 4, max 9): ");
  4. scanf("%d", &num_rows);
  5.  
  6. // valid entry check for rows
  7. while((num_rows < 4) || (num_rows > 9))
  8. {
  9. printf("\n\nInvalid entry, Please re-enter row size: ");
  10. scanf("%d", &num_rows);
  11. }
  12. printf("\nEnter number of columns. (min 4, max 9): ");
  13. scanf("%d", &num_cols);
  14.  
  15. // valid entry check for columns
  16. while((num_cols < 4) || (num_cols > 9))
  17. {
  18. printf("\n\nInvalid entry, Please re-enter row size: ");
  19. scanf("%d", &num_cols);
  20. }
  21.  
  22. // memory allocation based on user defined board size
  23. ptr2d = (char *)malloc(sizeof(char)*num_cols*num_rows);
  24. board_ptr = ptr2d;
  25.  
  26. // clean allocated memory and assign a generic filler
  27. for (j = 0; j <= num_cols; j++)
  28. for (i = 0; i <= num_rows; i++)
  29. *board_ptr[i][j] = "*"; //<------problem here


I tried several different ways like:
  1. board_ptr[i][j] ="*"
  2. *(board_ptr[i][j]) ="*"
  3. (*board_ptr[i][j]) ="*"
and I'm using Borland C++ builder 5.
Last edited by WolfPack; Apr 2nd, 2007 at 7:28 pm. Reason: [CODE][/CODE] tags
Reply With Quote Quick reply to this message  
Join Date: Dec 2005
Posts: 5,850
Reputation: Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute Salem has a reputation beyond repute 
Solved Threads: 749
Team Colleague
Salem's Avatar
Salem Salem is offline Offline
Void main'ers are DOOMed

Re: dynamic memory allocation

 
0
  #2
Apr 2nd, 2007
Apparently
http://www.daniweb.com/techtalkforum...cement8-3.html

Isn't in a big enough font, all the noobs keep missing the point.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 3
Reputation: negbballer54 is an unknown quantity at this point 
Solved Threads: 0
negbballer54 negbballer54 is offline Offline
Newbie Poster

Re: dynamic memory allocation

 
0
  #3
Apr 2nd, 2007
lol sorry.
Reply With Quote Quick reply to this message  
Join Date: Apr 2007
Posts: 3
Reputation: negbballer54 is an unknown quantity at this point 
Solved Threads: 0
negbballer54 negbballer54 is offline Offline
Newbie Poster

Re: dynamic memory allocation

 
0
  #4
Apr 2nd, 2007
Figured it out, needed to use pointer notation.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC