Practice

Log File Error Summary

HARDFile Handling10 marks

Read N log entries, write them to a file called log.txt, then read the file back and count the entry types.

Each log entry starts with one of these letters:

  • E for error
  • W for warning
  • I for information

Output the number of errors, warnings, and information entries.

Input: N followed by N log entry strings. Output: Three summary lines.

Example:

Input:  4
        E Disk full
        W Low memory
        I Start
        E Timeout
Output: Errors: 2
        Warnings: 1
        Info: 1
Premium is coming soon. All grading features are currently unlocked.

Sample Test Cases

Test 1: Mixed log entries
Inputs: 4, E Disk full, W Low memory, I Start, E Timeout
Expected: Errors: 2 Warnings: 1 Info: 1
Test 2: Only information entries
Inputs: 3, I Start, I Ready, I Stop
Expected: Errors: 0 Warnings: 0 Info: 3