-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadability_checking.c
More file actions
75 lines (69 loc) · 1.69 KB
/
Copy pathReadability_checking.c
File metadata and controls
75 lines (69 loc) · 1.69 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
65
66
67
68
69
70
71
72
73
74
75
#include<stdio.h>
#include<string.h>
#include<math.h>
#define MAX_TEXT_LENGTH 1000
char text[MAX_TEXT_LENGTH];
int count_letters(char *sentence);
int count_words(char *sentence);
int count_sentences(char *sentence);
int main(){
printf("text: ");
fgets(text, sizeof(text), stdin);
int letters = count_letters(text);
int words = count_words(text);
int sentences = count_sentences(text);
float L = (float) letters / words * 100;
float S = (float) sentences / words * 100;
float index = 0.0588 * L - 0.296 * S - 15.8;
int grade = round(index);
if (grade > 16)
{
printf("Grade 16+\n");
}
else if (grade < 1)
{
printf("Before Grade 1\n");
}
else
{
printf("Grade %d\n", grade);
}
return 0;
}
int count_letters(char *sentence)
{
int letters = 0;
while (*sentence) {
if ((*sentence >= 'a' && *sentence <= 'z') || (*sentence >= 'A' && *sentence <= 'Z')) {
letters++;
}
sentence++;
}
return letters;
}
int count_words(char *sentence)
{
int space = 0;
int length = strlen(sentence);
for(int i=0;i<length;i++)
{
if(*sentence == ' ')
{
space++;
}
sentence++;
}
int words = space + 1;
return words ;
}
int count_sentences(char *sentence)
{
int sentences = 0;
while (*sentence) {
if (*sentence == '.' || *sentence == '!' || *sentence == '?') {
sentences++;
}
sentence++;
}
return sentences;
}