hey everyone,
i am having trouble with this project. I have gotten off to a small start, but don't really know if i am in in or going in the right direction, anything helps!!
Project:
For this project, download the text file weblog.txt
Note: To download this file, right click on the link and select SAVE AS or SAVE TARGET AS
This file is an Apache web log taken from the web server for St. Mary's University. When a visitor goes to their web site, the visitor's browser makes a request to the web server to view a web page, which is a file residing on the server. Each time a page is requested by a browser, the web server records information about that request. This weblog.txt holds the details of some of those requests. See below for a list of fields with an example:
Web Log Example
This file does not include all possible information that could be collected by a web server. The full description of the apache log file format can be found here:
http://httpd.apache.org/docs/2.2/logs.html (Links to an external site.)Links to an external site.
For this project, you can use each line of the web log file as one string using the string class' getline function.
Minimum Requirements:
Create a function to read each line of the web log file (3 points).
Each line should then be stored in an array (your choice) such that the first element of the container is the first line of the web log file. Because each element will hold an entire line from the file, the container you choose should be declared with a data type of string (3 points). Note: You must declare the array in a function (main function or any other function). Declare the array with a size of 3000.
Create another function to write the first 10 lines in the container to a file called topTen.txt.
Create another function that will accept an integer line number in the parameter list and string return value. When the function is called in main, a line number must be passed to the function. The function should then return the line from the container that corresponds to that line number. You must pull the line from the container, not from the file. Because you are required to pull the line from the container, you must include the container in the parameter list of this function and pass the container to this function when it is called by main. The main function should then display the string that is returned by the function.
my code so far:
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
void myLine(){
string line;
string myArray[3000];
int numuse = 0;
ifstream myFile("weblog.txt");
if (myFile.is_open()) {
while (getline(myFile, line)) {
myArray[numuse++] = line;
}
myFile.close();
cout << myArray[3000];
} else {
cout << "File not found";
}
}
int main(){
myLine();
}