hey all
well i have been facing this problem for days ...i have written a program where i am suppose to read a specific number of lines within different intervals and count the number of occurance of r and s and then divide r by s. The program is running correctly but the problem takes place in such a case where s line is at the end of the interval and r line is received at the begining of the second interval giving me a % higher than 100 therefore i need to remove the last line of the interval and the first line of the second interval
plz help

ok will post now

Yes, it should allow you to paste code; what browser are you using?

If you look at the editing window, you should see a button marked 'Code'. If you click on that, it will come up with a pop-up window for editing the code in. If you have pop-ups blocked, or are using NoScript or a similar script blocker, that could be the cause of the problem.

Note also that you may not need to paste the whole program, if there is a specific function or section that you know is the source of the issue.

thank u here 's the code

#include <iostream>
#include <fstream>
#include <iomanip>
#include <cmath>
#include <string>
#include <sstream>
#include <vector>

    using namespace std;

int main()
{
    ofstream fout("TPDR[3-4-30].tr");
    ifstream fin("TTEST.tr");// if u use this as ur input file u will always get ur num as 6 because the range stops at 50 therefore u will get the throughputs calculated as 0z 
    ofstream fOut("TPDR30(3-4).tr");
    ofstream MYFILE("TPDR(3-4).tr");

    if (!fin)
    {
        cout << "input file not open" << endl;
        return 1;
    }

    fout << fixed << setprecision(9);
    fOut << fixed << setprecision(9);
    cout << fixed << setprecision(9);
    MYFILE << fixed << setprecision(9);

    double timelimit = 0.0;    // ending time of first block of data
    double timeincr  = 10.0;   // duration of each block of data

    string s1, s2, s3, sequenceno1,sequenceno2, s4, s5; // dummy variables to hold unwanted data 
    string line,oldline;

    char   type;   
    double time;   
    int    bytes;  
    int num = 0;
    istringstream ss;
    double received[21] = {0.0}; 
    double send[21] = {0.0}; 
    int drop[21] = {0}; 
    double Re[21]= {0.0};
    double Se[21] = {0.0};
    double De[21] = {0.0};
     int R = 0;
     int S = 0;
    double PDR =0.0;
    double PDRR[21] = {0.0};
    int Range; 


    //------- Priming read. Get first line.
    getline(fin, line);
    ss.str(line);
    ss >> type >> time;

    while (fin)
    {
        while (ss && time <= timelimit)
        {

            //------------- process the line here ------------------
                 // ss >> s1 >> s2  >> s3 >> s4 >> s5 ;



         if (type == 's') {

                  ss >> s1 >> s2 >> s3 >> sequenceno1 >> s4 >> s5;
                      oldline = line;
                      send[num]++; 
                      S = send[num]; 
                      Se[num] = S; 
                  }


               if (type =='r') {

                      ss >> s1 >> s2 >> s3 >> sequenceno2 >> s4 >> s5;
                  if ((time < timelimit)&&(sequenceno1 == sequenceno2)) {
                      cout << sequenceno1 << "   " << sequenceno2 << "    " << time << "    " << timelimit << ".\n";
                     received[num]++;
                     R = received[num];
                     Re[num] = R;
                     PDR = Re[num]/ Se[num];
                     PDRR[num] = PDR*100;

    fout << "Received = " << Re[num] <<"     " << time <<"    " << "Send= " << Se[num] << "  " << "Packet Delivery Ratio" << PDRR[num]  << "    "<< "sequenceno1 =" << sequenceno1 << "      "<< "sequenceno2 ="  << sequenceno2 << ".\n"; 


                }

                }

            //------------- end of process, now read the next line -----

            if (getline(fin, line))
            {
                ss.clear();             // clear all flags
                ss.str(line);
                ss >> type >> time;
            }
            else
            {
                ss.clear(ios::failbit); // set the fail flag

            }

        }



        timelimit += timeincr; // increment limit to next value
        cout << timelimit << ".\n\n";
        num++; 
        fout << "\n------------------\n";
        fout << "time limit: " << timelimit << endl;
        cout << "num = " << num << ".\n";
    } 

   // ..... Writting the Range and PDR within each Range in a separate File .....

for (Range = 10,num =1; Range <= 200, num <=20; Range+=10, num++) {
    fOut << Range << "     " << PDRR[num] << ".\n";
 } 

 double average = 0.0;
 double TPDR = 0.0;

 for (num = 1; num <=20 ; num++) {   // For loop to compute the Total PDR within each Range 
     TPDR += PDRR[num]; 
    // cout << "TPDR" << TPDR << "%" << ".\n"; 
 }

 average = TPDR /(num-1);
 cout << "average = " << average << "%" <<  ".\n";// Compute Average PDR 

    cout << "Done" << endl;
    return 0;
}

here's the file i am using

s 167.204369958 7 MAC --- 29867 tcp 630 [13a 8 7 800] ------- [7:2 8:1 32 8] [330 0] 0 1..
r 167.209410087 8 MAC --- 29867 tcp 572 [13a 8 7 800] ------- [7:2 8:1 32 8] [330 0] 1 1..
s 167.212674795 7 MAC --- 29868 tcp 630 [13a 8 7 800] ------- [7:2 8:1 32 8] [331 0] 0 1..
r 167.217714923 8 MAC --- 29868 tcp 572 [13a 8 7 800] ------- [7:2 8:1 32 8] [331 0] 1 1..
s 169.998902881 7 MAC --- 30344 tcp 630 [13a 8 7 800] ------- [7:3 9:0 32 8] [147 0] 0 1..
r 170.00392963 8 MAC --- 30344 tcp 572 [13a 8 7 800] ------- [7:3 9:0 32 8] [147 0] 1 1..
s 170.162989092 7 MAC --- 30466 tcp 630 [13a 8 7 800] ------- [7:2 8:1 32 8] [334 0] 0 1..
r 170.168029172 8 MAC --- 30466 tcp 572 [13a 8 7 800] ------- [7:2 8:1 32 8] [334 0] 1 1..
s 170.181482383 7 MAC --- 30467 tcp 630 [13a 8 7 800] ------- [7:2 8:1 32 8] [335 0] 0 1..
r 170.186522463 8 MAC --- 30467 tcp 572 [13a 8 7 800] ------- [7:2 8:1 32 8] [335 0] 1 1..
s 178.013133357 7 MAC --- 32131 tcp 630 [13a 8 7 800] ------- [7:2 8:1 32 8] [340 0] 0 1..
r 180.725285180 8 MAC --- 32716 tcp 572 [13a 8 7 800] ------- [7:2 8:1 32 8] [341 0] 1 1..

The problem takes place in such case where the s lines comes at the end of my range and the r lines comes at the begining of the second range leading to an increase in the number of the received lines than the send which gives a % higher than 100%
in this snapshot example i want to delete these two lines
s 169.998902881 7 MAC --- 30344 tcp 630 [13a 8 7 800] ------- [7:3 9:0 32 8] [147 0] 0 1..
r 170.00392963 8 MAC --- 30344 tcp 572 [13a 8 7 800] ------- [7:3 9:0 32 8] [147 0] 1 1..

plz help me out its annoying me for days
thanx in advance

The first step in solving a problem is a clear statement of what is required.

You wrote this at the top:

... been facing this problem for days ... have written a program where ... suppose to read a specific number of lines

within different intervals

What does this

within different intervals

mean?

Does it mean, as you read a file, line by line, counting the lines, from say line 1 as the first line ...

that you are take some (user specified) 'sample of lines' ... say lines n to line (n+size-1)

(You could copy these lines into a tmp vector of lines ... and pause your file scanning while you process that tmp vector ...)

and count the number of occurance of r and s

Ok ... process that tmp vector of lines, and report

and then divide r by s.

If that is 'your problem' ... can you see now that it is easy to handle it this way?

thank u 4 ur reply .... well what i meant by interval is the range of time say for example i have a file of 200s i should read my lines every 10s (in the ex above my first interval is from 160-170 and my second interval is from 170-180 and so on. The problem takes place when the s line comes at the end of the first interval and the r line comes at the begining of the second interval ...This will lead to incorrect counting as the number of r lines are suppose to be less than the s lines
i need to check if the s line comes at the end of the interval and is not followed by the r within the same interval if so delete
In the second interval i need to check if the interval starts with the r line and not s if so delete it
These lines are not at the end of my file therefore any ideas how can i do putting in consideration that my file is big
thanx in advance

Ok ...

still not clear what you are trying to do ...

suppose you have lines in a big file that look like this:

sxxxxxxxxxxxxxx...
rxxxxxxxxxxxxx...
rxxxxxxxxxxxxxx....
sxxxxxxxxxx............
sxxxxxxxxxxxxxx............
r............

to 100,000,000 + lines

ok ... suppose you are taking 2 successive samples for the intervals of 0.001 seconds each

you could read in all the lines into a list of lines ...for 0.002 secs ....

then process that list ... 1st half & 2nd half