DescriptionQ447
Q447FWAMDASIC interview problem
Count errors in a build report
TechniquesFirmware & ValidationFirmware / Validationcount errors in a build report
DifficultyEasy
TopicFirmware & Validation
LanguageC++
Requirements4 checkpoints
01
Problem
A build tool returns a byte buffer containing newline-separated log records; the buffer is not NUL-terminated. Write the C++ parser that counts records beginning with ERROR: and WARNING:.
Starting declarationC++
struct Counts { size_t errors, warnings; };
int count_log(const char *p, size_t n, Counts *out);Example input and output
Use this case to check your interpretationInput
A 20-byte buffer containing "ERROR: a\nWARNING: b\n".Output
Return 0 with errors=1 and warnings=1.Explanation
Each newline-delimited record begins with one exact uppercase prefix, so the bounded parser increments each counter once without needing a NUL terminator.
02
Requirements (4)
- Require out; p may be NULL only when n=0. Invalid arguments return -1 and preserve *out.
- A record starts at byte zero or immediately after '\n' and ends before the next '\n' or at n.
- Count a record only when its first bytes exactly match uppercase ERROR: or WARNING:; leading spaces do not match.
- Treat '\r' as an ordinary byte except that a trailing '\r' before '\n' does not affect prefix matching; write *out once and return 0.
