int * Help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2007
Posts: 84
Reputation: balla4eva33 is an unknown quantity at this point 
Solved Threads: 0
balla4eva33's Avatar
balla4eva33 balla4eva33 is offline Offline
Junior Poster in Training

int * Help

 
0
  #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?
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,562
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1484
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: int * Help

 
0
  #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.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 84
Reputation: balla4eva33 is an unknown quantity at this point 
Solved Threads: 0
balla4eva33's Avatar
balla4eva33 balla4eva33 is offline Offline
Junior Poster in Training

Re: int * Help

 
0
  #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 Quick reply to this message  
Join Date: Nov 2007
Posts: 84
Reputation: balla4eva33 is an unknown quantity at this point 
Solved Threads: 0
balla4eva33's Avatar
balla4eva33 balla4eva33 is offline Offline
Junior Poster in Training

Re: int * Help

 
0
  #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 Quick reply to this message  
Join Date: Aug 2005
Posts: 15,562
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1484
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: int * Help

 
0
  #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];
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 647
Reputation: jaepi is an unknown quantity at this point 
Solved Threads: 4
jaepi's Avatar
jaepi jaepi is offline Offline
Practically a Master Poster

Re: int * Help

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

Re: int * Help

 
0
  #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 Quick reply to this message  
Join Date: Aug 2005
Posts: 15,562
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1484
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is online now Online
Still Learning

Re: int * Help

 
0
  #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 10:09 am.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Feb 2006
Posts: 492
Reputation: Bench has a spectacular aura about Bench has a spectacular aura about Bench has a spectacular aura about 
Solved Threads: 49
Bench's Avatar
Bench Bench is offline Offline
Posting Pro in Training

Re: int * Help

 
0
  #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 11:20 am.
¿umop apisdn upside down?
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 37
Reputation: neosomosis is an unknown quantity at this point 
Solved Threads: 0
neosomosis's Avatar
neosomosis neosomosis is offline Offline
Light Poster

Re: int * Help

 
0
  #10
Dec 18th, 2007
My mistake...DMA - Dynamic Memory Allocation.
Reply With Quote Quick reply to this message  
Reply

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


Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC