User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 397,855 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,380 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser:
Views: 637 | Replies: 10
Reply
Join Date: Nov 2007
Posts: 80
Reputation: balla4eva33 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
balla4eva33's Avatar
balla4eva33 balla4eva33 is offline Offline
Junior Poster in Training

int * Help

  #1  
Dec 17th, 2007
So I've got "m_starts" as a pointer to an int (int * m_starts.
And a const char * of "m_str".

m_str = "bad,cold,new".

How can I allocate "m_starts" to store the starting index of each word in m_str???

For loop?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,644
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 36
Solved Threads: 867
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Most Valuable Poster

Re: int * Help

  #2  
Dec 17th, 2007
First you have to find out how many comma-separated words are in the string. Iterate through the string and count the commans. Then allocate the int array large enough to hold that many integers. After that, go through the string agsin, this time when you find a comma set one of the integers to be the numeric value of where the comma was found.

For example in the string you posted you will need three integers because the string contains three comma-separated words. The first integer will be 0, the second integer 4 and the 3d integer is 9.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Reply With Quote  
Join Date: Nov 2007
Posts: 80
Reputation: balla4eva33 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
balla4eva33's Avatar
balla4eva33 balla4eva33 is offline Offline
Junior Poster in Training

Re: int * Help

  #3  
Dec 17th, 2007
Understood, but what I'm asking is how do i allocate it to the size i want (in this case 3)??
Reply With Quote  
Join Date: Nov 2007
Posts: 80
Reputation: balla4eva33 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
balla4eva33's Avatar
balla4eva33 balla4eva33 is offline Offline
Junior Poster in Training

Re: int * Help

  #4  
Dec 17th, 2007
I mean I can set "m_starts[3];" or even run through a for loop so i leave it open to any number of sizes, but what I DON'T understand is how to then use it to store the starting index of each word in m_str. How do i go about that process??
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,644
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 36
Solved Threads: 867
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Most Valuable Poster

Re: int * Help

  #5  
Dec 17th, 2007
>>how do i allocate it to the size i want
This is c++ so use the new operator to allocate the array
m_starts = new int[NumberOfIntegers];
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Reply With Quote  
Join Date: Jul 2006
Location: Oblivion
Posts: 647
Reputation: jaepi is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 4
jaepi's Avatar
jaepi jaepi is offline Offline
Practically a Master Poster

Re: int * Help

  #6  
Dec 18th, 2007
dont forget to use delete to deallocate the memory.
Last edited by jaepi : Dec 18th, 2007 at 12:52 am.
Retreat!!!
Reply With Quote  
Join Date: Dec 2007
Location: Port Dickson, Malaysia
Posts: 37
Reputation: neosomosis is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
neosomosis's Avatar
neosomosis neosomosis is offline Offline
Light Poster

Re: int * Help

  #7  
Dec 18th, 2007
But I though DMA is for integers contain in an array only? Characters won't work for DMA....I've tried it before
Reply With Quote  
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 10,644
Reputation: Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of Ancient Dragon has much to be proud of 
Rep Power: 36
Solved Threads: 867
Moderator
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Most Valuable Poster

Re: int * Help

  #8  
Dec 18th, 2007
Originally Posted by neosomosis View Post
But I though DMA is for integers contain in an array only? Characters won't work for DMA....I've tried it before


Huh? I assume DMA means Direct Memory Address. How does that relate to the discussion of this thread ? BTW DMA is not possible with any 32-bit compiler unless writing a kernel-mode device driver.
Last edited by Ancient Dragon : Dec 18th, 2007 at 9:09 am.
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Reply With Quote  
Join Date: Feb 2006
Location: UK
Posts: 468
Reputation: Bench has a spectacular aura about Bench has a spectacular aura about Bench has a spectacular aura about 
Rep Power: 5
Solved Threads: 42
Bench's Avatar
Bench Bench is offline Offline
Posting Pro in Training

Re: int * Help

  #9  
Dec 18th, 2007
Originally Posted by Ancient Dragon View Post
Huh? I assume DMA means Direct Memory Address. How does that relate to the discussion of this thread ? BTW DMA is not possible with any 32-bit compiler unless writing a kernel-mode device driver.

I think he means 'Dynamic Memory Allocation' - I could be wrong though. Either way, it works fine with both char and int
Last edited by Bench : Dec 18th, 2007 at 10:20 am.
¿umop apisdn upside down?
Reply With Quote  
Join Date: Dec 2007
Location: Port Dickson, Malaysia
Posts: 37
Reputation: neosomosis is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
neosomosis's Avatar
neosomosis neosomosis is offline Offline
Light Poster

Re: int * Help

  #10  
Dec 18th, 2007
My mistake...DMA - Dynamic Memory Allocation.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb C++ Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the C++ Forum

All times are GMT -4. The time now is 8:31 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC