Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post Posted: November 27th, 2014, 2:46 pm 
 

Joined: December 4th, 2013, 2:58 pm
Posts: 25
So i have a string (example : "1 12 69 123") and i want to put each of the space separated integers into an array of integers . the number of integers is known ( in this case 4 ) . Thanks in advance :3

Ps . i know it's not relevant to the framework . don't be too mad :(

Ps2 . array of std::vector is also acceptable


Top 
 Profile  
Reply with quote  
 Post Posted: November 27th, 2014, 4:37 pm 
 

Joined: June 26th, 2012, 5:38 pm
Posts: 765
Location: USA
unsigned int NDigits( int num )
{
return log10(num) + 1;
}

char buffer[100] = "(your string here)";
std::vector<int> nums;
unsigned int index = 0;
const unsigned int size = strlen(buffer);
while(index < size)
{
nums.push_back(atoi(&buffer[index]));
index += (NDigits(nums.back()) + 1);
}

Note you must include math.h

Just curious are you in a programming class?
Try that out, good luck!

_________________
Computer too slow? Consider running a VM on your toaster.


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 2 posts ] 

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: