-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3.cpp
More file actions
64 lines (46 loc) · 1.23 KB
/
Copy path3.cpp
File metadata and controls
64 lines (46 loc) · 1.23 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
@Author: Amritanshu Sikdar
Session: 2018-'19
Repository: https://github.com/amritanshusikdar/CS30PracticalQuestion
*/
// Program to store sentences in a text file and print number of "To" & "The" in it.
#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<fstream.h>
#include<stdlib.h>
void main()
{
clrscr();
int to = 0, the = 0, flag = 0;
char letter, word[10];
fstream count("SENT.TXT", ios::in | ios::out);
if(count.bad())
{
cout << "Error opening file! \nExiting now..." << endl;
getch();
exit(0);
}
cout << "Enter your sentence: (Press ESC to exit)" << endl;
while(flag == 0)
{
letter = cin.get();
if(letter == 27) // ASCII value of ESC (escape) key
flag = 1;
else count << letter;
}
// Counting number of To and The
count.seekg(0,ios::beg); // Setting the file pointer to the beginning of file
while(!count.eof())
{
count >> word;
if(strcmpi(word, "the") == 0)
the++;
if(strcmpi(word, "to") == 0)
to++;
}
cout << "Total TO: " << to << endl;
cout << "Total THE: " << the << endl;
count.close();
getch();
}