-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path156.cpp
More file actions
64 lines (57 loc) · 1.08 KB
/
156.cpp
File metadata and controls
64 lines (57 loc) · 1.08 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
#include<stdio.h>
#include<stdlib.h>
#include<fcntl.h>
#include<unistd.h>
#include<iostream>
using namespace std;
class openFile
{
public:
int fd;
openFile(char name[])
{
fd=open(name,O_RDONLY);
if(fd==-1)
{
cout<<"Unable to open file"<<endl;
}
else
{
cout<<"File Opened Successfully"<<endl;
}
}
int Displaychar(char ch[])
{
char Arr[10];
int ret=0;
int iCnt=0;
while((ret=read(fd,Arr,10))!=0)
{
for(int i=0;i<ret;i++)
{
if(Arr[i]==ch[i])
{
iCnt++;
}
}
}
return iCnt;
}
~openFile()
{
close(fd);
}
};
int main()
{
char str1[20],str2[30];
int iRet=0;
cout<<"Enter File name"<<endl;
cin>>str1;
cout<<"Enter the Word that you want to search"<<endl;
cin>>str2;
openFile obj(str1);
iRet=obj.Displaychar(str2);
cout<<"count of "<<str2<<" is "<<iRet<<endl;
return 0;
}