Thread: Show log entries in a date range

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    54

    Show log entries in a date range

    I have a problem here with a log file I read in. Basically, the function takes in two strings (startdate, enddate) and should output all the log entries of the file that's being read in (a log file, each line is formatted "Day of the week" "Date" "Time" "user" "message"). For example, if startdate is 01/01/2005 and enddate is 01/31/2005, then the fuction should print out all the entries between these two dates.

    How should I go about doing this? From just thinking about it, I'm lead to believe that I need to convert the strings startdate and enddate into time objects, correct?

    Thanks .
    -Zack

  2. #2
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    Assuming that the two dates are strings and the log file stores dates as strings, a lexical comparison would be a good starting point:
    Code:
    while (read_record(rec)) {
      if (rec.date >= startdate && rec.date < enddate)
        std::cout<< rec <<'\n';
    }
    My best code is written with the delete key.

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    54
    Quote Originally Posted by Prelude
    Assuming that the two dates are strings and the log file stores dates as strings, a lexical comparison would be a good starting point:
    Code:
    while (read_record(rec)) {
      if (rec.date >= startdate && rec.date < enddate)
        std::cout<< rec <<'\n';
    }
    Understood. Now, can you explain (or link me) to what a lexical comparison is? I'm fairly new to C++, as you can tell by the level of my posts .
    -Zack

  4. #4
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,897
    >Now, can you explain (or link me) to what a lexical comparison is?
    Just compare the two strings and the right thing should happen.
    My best code is written with the delete key.

  5. #5
    Registered User
    Join Date
    May 2005
    Posts
    54
    Alright, thanks bud. I will try that once I get to the office.
    -Zack

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Missing Entries in Hashtable
    By wuzzo87 in forum C Programming
    Replies: 3
    Last Post: 05-13-2007, 12:46 AM
  2. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 01:04 AM
  3. fprintf works in one function but not in the other.
    By smegly in forum C Programming
    Replies: 11
    Last Post: 05-25-2004, 03:30 PM
  4. My log file player; Hit the brick wall
    By Twig in forum C Programming
    Replies: 6
    Last Post: 07-27-2002, 05:35 PM
  5. date class
    By aquaman in forum C++ Programming
    Replies: 3
    Last Post: 10-10-2001, 09:57 AM