-
Notifications
You must be signed in to change notification settings - Fork 0
/
filewr4.c
53 lines (40 loc) · 1.07 KB
/
filewr4.c
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
#include<stdio.h>
#include<fcntl.h>
#include<unistd.h>
#include<string.h>
void createFile(char* filename, char* alphabet);
char* readFile(char* filename, char* read);
int openFile(char *);
int getAlphabetCount(char* filename);
int main() {
char filename[1024] = "temp0.txt";
char fileContent[1024] = "dong dong dong";
createFile(filename, fileContent);
int count = getAlphabetCount(filename);
printf("%d", count);
return 0;
}
int getAlphabetCount(char* filename) {
char read[1024] = {};
readFile(filename, read);
int count;
for (int i = 0; i < strlen(read); ++i) {
if ((read[i] <= 90 && read[i] >= 65) || (read[i] <= 122 && read[i] >= 97)) {
count++;
}
}
return count;
}
void createFile(char* filename, char* alphabet) {
int fd = openFile(filename);
char* a = alphabet;
write(fd, a, 100);
close(fd);
}
char* readFile(char* filename, char* ret) {
int fd = openFile(filename);
read(fd, ret, 100);
}
int openFile(char *filename) {
return open(filename, O_RDWR | O_CREAT, 0664);
}