-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchallenge5.cpp
45 lines (40 loc) · 1.01 KB
/
challenge5.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/* Line Count Challenge
Here's a simple help free challenge to get you started: write a program that takes a file as an argument and counts the total number of lines.
Lines are defined as ending with a newline character. Program usage should be
count filename.txt
and the output should be the line count. */
#include <iostream>
#include <fstream>
#include <string>
#include <conio.h>
using namespace std;
int main(int argc,char *argv[])
{
string filename;
string text;
int i = 0;
if (argc != 2)
{
cout << "What is the filename? ";
cin >> filename;
cout << endl;
}
else filename = argv[1];
ifstream filenameCount;
filenameCount.open (filename.c_str());
if (filenameCount.fail())
{
cout << "Error, could not open file " << filename;
return 1;
}
filenameCount.seekg(0);
while (!filenameCount.eof())
{
getline(filenameCount, text);
i++;
}
filenameCount.close();
cout << "size is: " << (end-begin) << " bytes.\n";
getch();
return 0;
}