I'm so sorry if this question already is answered. If it is, please direct me to the solution.
I'm currently trying to go through a text file, iterate through it to find a numeric value, pipe the value into a child/parent process, where I then return the updated value into a text. As simple as it is, I'm trying to find the numbers and either put them into an array/string, so I can feed it to a pipe and then feed it back into the text. I have been working on this for 5 days, so I'm finally asking you guys for help. Again, apologies if this already exists.
I'm currently going through the text and checking each character if it's an integer. I'm able to put it into a string, but it's just one big long string. I'm not sure how else to implement it.
This is what I have so far.
while(!readText.eof())
{
while(getline(readText, item))
{
readText >> item;
for(int i=0; i < item.length(); ++i){
if(isdigit(item[i])) //checking if it is a digit
newitem += item[i]; //puts into string
if(!isdigit(item[i])) // if it's not a digit feed it out (but maybe I
//should put into new variable?
cout << item[i];
else if(isspace(item[i]))//keeps the spaces as cout, but again, maybe
//put it into a variable?
cout << " ";
}
}
}
my challenge is trying to figure out how to separate the values and put them back. I would grow with the index, but the numbers will grow, so the position would not be as accurate.
Updated context
Thank you everyone for the help. A sample file would be
In the b6765lue sky there are 59 clouds. The gra7ss is green 766 and it 837 has 7 a cow in i87t.
I would need to change the numbers through a process/function. So like you mentioned the size of the numbers will naturally become larger. The test files can be 100s of lines.
In the b6789lue sky there are 83 clouds. The gra31ss is green 790 and it 861 has 31 a cow in i111t.
The values have been changed with 5 processes and and incremental value of 5.