Title: Simple Error logging
Title Description:
Develop a simple error logging function module that can record the file name and line number of the code where the error occurred.
Processing:
1, record up to 8 error records, circular record, the same error record (NET file name and line number exactly match) only one error recorded, error count increased;
2, more than 16 characters of the file name, only record the last valid 16 characters of the file;
3, the input file may take the path, the record file name cannot take the path
Input Description:
A line or multiline string. Each line includes a path file name, line number, separated by a space.
File path to Windows format
Example: E:\V1R2\product\fpgadrive.c 1325
Output Description:
Statistics and output of all records, format: Number of file name code lines, separated by a space, such as: FPGADRIVE.C 1325 1
Results are sorted according to the first occurrence of the input, depending on the number of orders, in the same number of times.
If more than 8 records are exceeded, only the first 8 records are printed.
If the file name is longer than 16 characters, only the first 16 characters are printed
Input Example:
E:\V1R2\PRODUCT\FPGADRIVE.C 1325
Output Example:
FPGADRIVE.C 1325 1
Topic Analysis:
① Topic First compare each error, if the same we only need to record one error, but the error count to add 1; so we thought about storing each error in a two-dimensional array of 8 rows and 17 columns store[8][17]
② we want to record the error count because each error may be different, so we also define a one-dimensional array counts[i]
③ more than 16 characters of the file name, we only record the last valid 16 characters of the file, so we want to distinguish the file name and the number of lines of Shurihu, so we need to define a one-dimensional array to save the wrong line number rows[]
④ detects the length of the file name, we need to move from the back to the number, the detection/character, here need to note that the C language relay literal character with a double right slash represents the escape character.
⑤ We also need a calculation that each error is not equal, we can use the string in the strcmp to compare, and the rows need to be equal, if the first input, we do not need to compare. Each entry is then compared with each previous one. Using loops to solve
⑥ if not equal, we will directly copy the string to the store, using string processing strcpy
⑦ final output format, by test instructions can know that we are here to output all of the previous errors, all of us to adopt A For loop, output all the errors. The error contains store[],rows[],counts[]
Study notes:
① full use of arrays to complete the algorithm
If there are many strings that need to be saved, we need to save them with a string array, a two-dimensional array, store[i] to represent a string
② full use of String functions strcpy copy and strcmp comparison
③ Note If we know the initial address of an array, I need to represent the string following the string we can represent &s[len-1-i]. Learn this way of expression
=============================================================================
Reference code:
//simple error logging. cpp#include <iostream>#include<string>using namespacestd;Const intMAXN = +;CharS[MAXN];intMain () {//Initialize Charstore[8][ -] = {0}; intcounts[8] = {0}; introws[8] = {0}; intRow,kase =0; //input while(Cin >> S >>row) { intLen =strlen (s); inti; //only 16 Characters of last valid character are reserved for(i =0; I < -; i++) { if(S[len-1-I] = ='\\') Break; } //Judging is not the samei--; intEqual =0; for(intj =0; J < Kase; J + +) { if(strcmp (Store[j],&s[len-1-I]) = =0&& row = =Rows[j]) {Equal=1; COUNTS[J]++; Break; } } //if not the same if(!equal) {strcpy (store[kase],&s[len-1-i]); Rows[kase]=Row; Counts[kase]++; Kase++; } for(intj =0; J < Kase; J + +) {cout<< Store[j] <<" "<< Rows[j] <<" "<< Counts[j] <<Endl; } } return 0;}
Transferred from: http://m.blog.csdn.net/blog/to_xidianhph_youth_2010/37419629
Read a lot of examples of the implementation of the error logging function, this is the most basic writing. Daniel is so good (I'm too much food). )。
[Go] Error Record