-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmani.c
More file actions
58 lines (47 loc) · 1023 Bytes
/
mani.c
File metadata and controls
58 lines (47 loc) · 1023 Bytes
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
#include <stdio.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
int size,i=0,n=0;
char value[30],buf[30];
printf("Enter the number of employees: \t");
scanf("%d",&size);
// creat file
int fd= open("employee.txt",O_RDWR|O_CREAT,0700);
if(fd == -1)
{
printf("Error existing now\n" );
exit(1);
}
printf("Enter the names of %d employees\n",size );
// Write contents into the file
while(size>0)
{
scanf("%s",value);
write(fd, value, strlen(value));
write(fd,"\n",strlen("\n"));
size--;
}
// Counting Section
lseek(fd,0,SEEK_SET);
while(read(fd,&buf[i],1)==1)
{
if(buf[i]=='\n')
{
// buf[i]=0;
if(buf[0]=='s')
{
n++;
}
i=0;
continue;
}
i++;
}
close(fd);
printf("Sucessfully exicuted\n" );
printf("%d Employees with starting letter S \n",n);
}