Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cs50.h>
- #include <stdio.h>
- #include <math.h>
- #include <string.h>
- #include <ctype.h>
- //declaring functions
- int count_letters(string text);
- int count_words(string text);
- int count_sentences(string text);
- int main(void)
- {
- string text = get_string("text: ");
- int letters = count_letters(text);
- int words = count_words(text);
- int sentences = count_sentences(text);
- float L;
- float S;
- float index;
- L = (float) (100 * letters) / words;
- S = (float) (100 * sentences) / words;
- index = (0.0588 * L) - (0.296 * S) - 15.8;
- printf("index: %f\n", index);
- }
- //function to count letters
- int count_letters(string text)
- {
- int letters = 0;
- int len = strlen(text);
- for(int i = 0; i < len; i++)
- {
- letters = letters + 1;
- }
- for(int j = 0; j < len; j++)
- {
- if (isspace(text[j]))
- {
- letters = letters - 1;
- }
- }
- return letters;
- }
- //function to count words
- int count_words(string text)
- {
- int spaces = 0;
- int words;
- int len = strlen(text);
- for(int j = 0; j < len; j++)
- {
- if (isspace(text[j]))
- {
- spaces = spaces + 1;
- }
- }
- words = spaces + 1;
- return words;
- }
- //function to count sentences
- int count_sentences(string text)
- {
- int len = strlen(text);
- int sentences = 0;
- for(int j = 0; j < len; j++)
- {
- if (ispunct(text[j]))
- {
- sentences = sentences + 1;
- }
- }
- return sentences;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement