Searching a file based on dates

Hi,
I have task like this.
I have a text file which has lines like this.
ProbNO, StartedBy,StartDate, Processed By,ProcessDate,EndedBy,EndDate.
The above is a general form of a single line.
The example entries in the file are like
1,John,1998/09/12,Jock,1998/09/13,Jill,1998/09/14
2,John,1998/09/13,Jock,1998/09/14,Jill,1998/09/15
3,John,1998/09/13,Jock,1998/09/14,Jill,1998/09/15
4,John,1998/09/14,Jock,1998/09/15,Jill,1998/09/16
5,John,1998/09/17,Jock,1998/09/18,Jill,1998/09/19
6,John,1998/09/20,Jock,1998/09/21,Jill,1998/09/22  

Like above.
The user from the inter face enters
Start Date :  1998/09/12
End Date   :  1998/09/16
and says OK.
I have to return a datewise problem numbers started and ended. i.e.
Date        Started   Ended
1998/09/12     1        0
1998/09/13     2        0
1998/09/14     1        1
1998/09/15     0        2
1998/09/16     0        1

That is the number of problems started on the date and the number of problems ended on that date for all dates.
 Hope this is clear.      

ardneyAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
vikajConnect With a Mentor Commented:
say you have the following string :
           I DO NOT LIKE STUDYING , PRICKING,HACKING.
           NOW YOU WANT TO EXTRACT THE PORTION "PRICKING"
        CHAR    X[100],Y[100];
        INT  A,B;
        A=0;
       B=0;
        L=STRLEN(X);
       WHILE ((X[A] !=','AND (A<L))
{
          A++
}
A++
DO WHILE (X[A] !=',')
         {
             Y[B]=X[A];
              B++;
              A++;
        }
       NOW YOU HAVE "PRICKING" IN Y.
        THIS IS ONLY THE REQ PART NOT THE WHOLE PROGRAM.
0
 
NorbertCommented:
Now I believe I understand what you want
0
 
vikajCommented:
what you can do is to treat the entries as separate records each having 6 fields
1>starter
2>start date
3>processed by
4>process date
5>ended by
6>end date
now you can sort the records on start date  field and within start date on end date field
since you don't need the other 4 fields here they are getting destroyed.however you can save the original file beforehand.NOW you have the input start date.search the table
on start date until you find a match.
here i give you an example
input   start date      end date
              14               15

    the sorted file
     start date          end date   otherfields
       14                     15
       14                      16
        14                     17
         15                   16
        15                     17
   and so on
       each time you meet 14 have s(14)++ if the end date is within the range then
have  e(15)++ you don't have to search any longer since end day>startday!!
  tell me whether you understand????
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
ardneyAuthor Commented:
I know the logic. But I am not in a position to keep it in the form of a c++ code.
some code will help.
0
 
NorbertCommented:
Use strtok to seperate the strings to the fields you have
because you have a fixed format you know which string belongs to which filed
0
 
ardneyAuthor Commented:
Some code will help
0
 
nietodCommented:
ardney, the problem is that we can only provide limited help on a schoolwork assignment.  We can answer SPECIFIC questions, like you might ask your teacher.  We can make general suggestions, and we can review your work and make criticisms.  If you would like to start the work and submit what you get, we can ofter some suggestions.   Or ask us SPECIFC questions.
0
 
ardneyAuthor Commented:
If I have a string and want to extract the characters after I encounter a comma, What I have to do?

0
 
gkibbleCommented:
String parsing, one of my favorite things about C++.  I like the Left and Mid CString functions but there are other ways to parse.

CString csMyString = ???;
int nPos = csMyString.Find( ',' );    // search for comma
CString csPreComma, csPostComma;

if ( nPos != -1 )
{
    csPreComma = csMyString.Left( nPos );
    csPostComma = csMyString.Mid( nPos + 1 );
}
else
{
   // comma not found
}

0
 
nietodCommented:
As norbert suggested  (spelling okay?  : - ) )

The strtok() procedure would be perfect for your purposes.  It returns a pointer to the next token (part of the string seperated by ',' in this case) in a string

You would use it like

char *FstTknPtr;
char *SecTknPtr;
char SrcStr[] = "first,second";

FstTknPtr = strtok(SrcStr,",");
SecTknPtr = strtok(SrcStr,',');

This makes FstTknPtr point to a string with "first" and SecTknPtr point to one with "second".

0
 
nietodCommented:
I was about to go on and suggest that strtok() is not the best way to do this (it is the easiest, but it is can cause you headaches), but I think gkibble is putting you on the right track.
0
 
gkibbleCommented:
I'll modify my code to mimick strtok on one line of data

CString csDataField[7];
CString csDataLine;
int nPos;
int nField = 0;

while ( (nPos = csDataLine( ',' ) ) != -1 )    // search for comma
{
   // get data before comma
    csDataField[ nField++ ] = csMyString.Left( nPos );

   // chop off field and comma from data line
     csDataLine = csDataLine.Mid( nPos + 1 );
}

This will break data line into 7 comma seperated fields
Note you should add null checks and make sure nField does not go above 6!

0
 
nietodCommented:
gkibble, you are using CString.  That is not standard C++.  I can assure you that this is not an MFC application.  You need to use the C++ string class.
0
All Courses

From novice to tech pro — start learning today.