Need major help

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Oct 2005
Posts: 8
Reputation: bucsoldier03 is an unknown quantity at this point 
Solved Threads: 0
bucsoldier03 bucsoldier03 is offline Offline
Newbie Poster

Need major help

 
0
  #1
Nov 14th, 2005
i have to convert a program from c++ to C language and at one point in my program im stuck where its dealing with dynamic memory of an array. i started it but i dont know how u do dynamic memomory in c language.



  1. if (reply == '1')
  2. {
  3. printf("Enter the 1st score (any invalid score to quit): ");
  4. scanf("%d", score);
  5. while (score >= 0 && score <= 100)
  6. {
  7. ++numOfScores;
  8. if (numOfScores > arraySize)
  9. {
  10. arraySize = int(1.5*arraySize + 1);
  11. scoresArrayPtrHold = scoresArrayPtr;
  12. scoresArrayPtr = new int [arraySize];
  13. for (int i = 0; i < numOfScores - 1; ++i)
  14. *(scoresArrayPtr + i) = *(scoresArrayPtrHold + i);
  15. free(scoresArrayPtrHold);
  16. scoresArrayPtrHold = 0;
  17. }
  18. *(scoresArrayPtr + numOfScores - 1) = score;
  19.  
  20. printf("Enter the next score (any invalid score to end): ");
  21. scanf("%d", score);
  22. }
Last edited by Dave Sinkula; Nov 14th, 2005 at 10:25 pm. Reason: Added [code][/code] tags.
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 1,496
Reputation: WolfPack has a spectacular aura about WolfPack has a spectacular aura about WolfPack has a spectacular aura about 
Solved Threads: 104
Moderator
WolfPack's Avatar
WolfPack WolfPack is offline Offline
Mentally Challenged Mod.

Re: Need major help

 
0
  #2
Nov 14th, 2005
search for the malloc, calloc, realloc functions.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 598
Reputation: SpS is on a distinguished road 
Solved Threads: 32
SpS's Avatar
SpS SpS is offline Offline
Posting Pro

Re: Need major help

 
0
  #3
Nov 14th, 2005
you'll find good tutorials on this site itself
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 8
Reputation: bucsoldier03 is an unknown quantity at this point 
Solved Threads: 0
bucsoldier03 bucsoldier03 is offline Offline
Newbie Poster

Re: Need major help

 
0
  #4
Nov 22nd, 2005
whats that
Reply With Quote Quick reply to this message  
Join Date: Oct 2005
Posts: 8
Reputation: bucsoldier03 is an unknown quantity at this point 
Solved Threads: 0
bucsoldier03 bucsoldier03 is offline Offline
Newbie Poster

Re: Need major help

 
0
  #5
Nov 22nd, 2005
how do i get to the tutoriols
Reply With Quote Quick reply to this message  
Join Date: Apr 2004
Posts: 4,461
Reputation: Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future Dave Sinkula has a brilliant future 
Solved Threads: 255
Team Colleague
Dave Sinkula's Avatar
Dave Sinkula Dave Sinkula is offline Offline
long time no c

Re: Need major help

 
0
  #6
Nov 22nd, 2005
Originally Posted by bucsoldier03
how do i get to the tutoriols
http://www.daniweb.com/tutorials/forum21.html
"One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 78
Reputation: perniciosus is an unknown quantity at this point 
Solved Threads: 4
perniciosus's Avatar
perniciosus perniciosus is offline Offline
Junior Poster in Training

Re: Need major help

 
0
  #7
Nov 24th, 2005
Originally Posted by bucsoldier03
how do i get to the tutoriols
man is your friend...

(*hint man malloc)
Reply With Quote Quick reply to this message  
Join Date: Nov 2005
Posts: 251
Reputation: dwks has a spectacular aura about dwks has a spectacular aura about 
Solved Threads: 25
dwks's Avatar
dwks dwks is offline Offline
Posting Whiz in Training

Re: Need major help

 
0
  #8
Nov 25th, 2005
And don't forget free(), which I'm sure is mentioned in the tutorial.
dwk

Seek and ye shall find.

"Only those who will risk going too far can possibly find out how far one can go."
-- TS Eliot.

"I have not failed. I've just found 10,000 ways that won't work."
-- Thomas Alva Edison

"The only real mistake is the one from which we learn nothing."
-- John Powell
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum


Views: 1828 | Replies: 7
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC