From 9854c55593a05ad193318afe25b4d16710dc9f3f Mon Sep 17 00:00:00 2001 From: Krishnapal-rajput <72176093+Krishnapal-rajput@users.noreply.github.com> Date: Tue, 5 Oct 2021 10:08:25 +0530 Subject: [PATCH] Create readability.c It is a c program that grade the line of text according to marking schema. --- readability.c | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 readability.c diff --git a/readability.c b/readability.c new file mode 100644 index 0000000..5703bf4 --- /dev/null +++ b/readability.c @@ -0,0 +1,63 @@ +#include +#include +#include +#include +#include + + +int main(void) +{ + // Ask user for a line of text + string text = get_string("Text: "); + + // Find the length of given string + int i = strlen(text); + int letters = 0; + int words = 0; + int sentences = 0; + + // Count the letters using loop + for (int x = 0; x < i; x++) + { + // Counting letters + char c = text[x]; + if (isalpha(c) != 0) + { + letters++; + } + + // Now counts the words + if (c == ' ') + { + words++; + } + + // Count the sentence + if (c == '.' || c == '!' || c == '?') + { + sentences++; + } + } + + // To account for last word + words = words + 1; + + // Calculation + float L = ((float)letters / (float)words) * 100; + float s = ((float)sentences / (float)words) * 100; + float subindex = 0.0588 * L - 0.296 * s - 15.8; + int index = round(subindex); + if (index > 16) + { + printf("Grade 16+\n"); + } + else if (index < 1) + { + printf("Before Grade 1\n"); + } + else + { + printf("Grade %i\n", index); + } + +}