Okay, I have this program that needs to read in a file and output the contents in a file with specific parameters. The usage is as follows:
where MaxPages is where the user says how many they want to see, inFileName is the input file, and outFileName is the output file.
histogram.exe MaxPages inFileName outFileName
An example input would be:
I need to take this input and to the output file only the information after GET and either to the end of the line or to a "?"
188.8.131.52 - - [30/Mar/2008:23:31:21 -0500] "GET /cocoon/~cs330web/forum/show/_axle/private.gif HTTP/1.1" 302 -
184.108.40.206 - - [30/Mar/2008:23:31:21 -0500] "GET /cocoon/~cs330web/forum/show/_axle/feed-icon16x16.png HTTP/1.1" 302 -
220.127.116.11 - - [30/Mar/2008:23:31:21 -0500] "GET /axle/Forum/_axle/private.gif HTTP/1.1" 304 -
18.104.22.168 - - [30/Mar/2008:23:31:21 -0500] "GET /axle/Forum/fckeditor/editor/fckeditor.html?InstanceName=text&Toolbar=ForumToolbar HTTP/1.1" 304 -
22.214.171.124 - - [30/Mar/2008:23:31:21 -0500] "GET /axle/Forum/fckeditor/fckconfig.js HTTP/1.1" 304 -
127.0.0.1 - - [30/Mar/2008:23:31:28 -0500] "GET / HTTP/1.0" 200 2499
127.0.0.1 - - [30/Mar/2008:23:31:29 -0500] "GET / HTTP/1.0" 200 2499
Now, I currently have these 3 functions to do the stripping of the other information:
To extract the quoted request:
Check if it's a GET request:
string extractTheRequest(string logEntry)
string::size_type requestStart = logEntry.find('"');
string::size_type requestEnd = logEntry.rfind('"');
if (requestStart != requestEnd)
return logEntry.substr(requestStart+1, requestEnd-requestStart-1);
And extract the locator part:
bool isAGet (string request)
return request.size() > 3 && request.substr(0,4) == "GET ";
I am currently trying to write a function that stores the locator part of the request in 1 array and then counts the times a single locator is found in a second array. (essentially parallel arrays).
string extractLocator (string request)
// strip off the GET
string::size_type locatorStart = 3;
// Skip any blanks
while (request[locatorStart] == ' ')
// The locator ends at the first blank or ? after that.
string::size_type locatorEnd = locatorStart;
while (request[locatorEnd] != ' ' && request[locatorEnd] != '?')
string locator = request.substr(locatorStart, locatorEnd-locatorStart);
I can get the information stored in the arrays but it still has everything before the GET stored too which I don't want. Also, I can't get the counter to work either... Any help would be greatly appreciated! Thanks!