I'm making an app that reads through an input text file and shows the number of alphanumerical characters, punctuation marks, spaces, etc in the text. The problem is I can't figure out how to make it print out the contents of the file. It is only printing the amount of characters in the title of the text.

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

I'm making an app that reads through an input text file and shows the number of alphanumerical characters, punctuation marks, spaces, etc in the text. The problem is I can't figure out how to make it print out the contents of the file. It is only printing the amount of characters in the title of the text.

 

// Close input file
inFile.close( );
56
57
58
cout << endl << lineCount << " line(s) read from file '"
59
« INPUT_FILE_NAME << "'." « endl « endl;
60
61
}
62
63
//count number of alphanumeric char
64
65
alnum =0;
while (isalnum(INPUT_FILE_NAME [alnum])) alnum++;
printf ("Alphanumeric chars: %d \n",alnum);
66
67
68
69
70
71
// Show application close
72
cout << "End of Text Turtles" << endl;
73
74 }
75
Transcribed Image Text:// Close input file inFile.close( ); 56 57 58 cout << endl << lineCount << " line(s) read from file '" 59 « INPUT_FILE_NAME << "'." « endl « endl; 60 61 } 62 63 //count number of alphanumeric char 64 65 alnum =0; while (isalnum(INPUT_FILE_NAME [alnum])) alnum++; printf ("Alphanumeric chars: %d \n",alnum); 66 67 68 69 70 71 // Show application close 72 cout << "End of Text Turtles" << endl; 73 74 } 75
16
17 using namespace std; || So "std::cout" may be abbreviated to "cout"
18
19
int main()
20 {
21
// Declare constants
const string INPUT_FILE_NAME = ("SampleText1.txt");
22
23
24
// Declare variables
ifstream inFile;
25
26
27
int lineCount;
string line;
int alnum;
28
29
30
31
32
// Show application header
33
cout << "Welcome to Text Turtles" « endl;
34
cout << "-.
_" <« endl « endl;
35
// Attempt to open input file
inFile.open(INPUT_FILE_NAME);
if (!inFile.is_open())
cout << "Error: unable to open file '"
36
37
38
39
40
« INPUT_FILE_NAME << ""." « endl « endl;
41
else
42
{
43
// Loop to read from input file
cout <« "Reading lines from file '" « INPUT_FILE_NAME
44
45
46
.." << end1 « endl;
...
47
lineCount = 0;
48
while (inFile.good())
49
{
50
getline(inFile, line);
51
52
lineCount = lineCount + 1;
53
}
54
55
// Close input file
inFile.close();
cout << endl < lineCount << " line(s) read from file '"
56
57
58
Transcribed Image Text:16 17 using namespace std; || So "std::cout" may be abbreviated to "cout" 18 19 int main() 20 { 21 // Declare constants const string INPUT_FILE_NAME = ("SampleText1.txt"); 22 23 24 // Declare variables ifstream inFile; 25 26 27 int lineCount; string line; int alnum; 28 29 30 31 32 // Show application header 33 cout << "Welcome to Text Turtles" « endl; 34 cout << "-. _" <« endl « endl; 35 // Attempt to open input file inFile.open(INPUT_FILE_NAME); if (!inFile.is_open()) cout << "Error: unable to open file '" 36 37 38 39 40 « INPUT_FILE_NAME << ""." « endl « endl; 41 else 42 { 43 // Loop to read from input file cout <« "Reading lines from file '" « INPUT_FILE_NAME 44 45 46 .." << end1 « endl; ... 47 lineCount = 0; 48 while (inFile.good()) 49 { 50 getline(inFile, line); 51 52 lineCount = lineCount + 1; 53 } 54 55 // Close input file inFile.close(); cout << endl < lineCount << " line(s) read from file '" 56 57 58
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY