0
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>

int main (void)

{
   
    string text = get_string("Text: ");
    
    float num_letters, num_words, num_sentences;
   num_letters = num_words = num_sentences = 0;
   
   int len = strlen(text);
   for (int i = 0; i < len; i++)
   {
      
    if (isalpha(text[i]))
        num_letters ++;
    if (i==0 ; text[i] != ' ' ||( i != len-1 && text[i] == ' ' && text[i+1] != ' '))
        num_words ++;
    if (text[i]) == '.' || text[i] == '!' || text[i] == '?')
        num_sentences ++;
    }

   //The Coleman Liau index
    num_letters = 100 * (num_letters/ num_words);
    num_sentences = 100 * (num_sentences/ num_words);
     int index = round(0.0588 * num_letters - 0.296 * num_sentences - 15.8);
    // print the grade
    if (index < 1) {
        printf("Under grade 1.");
    }
    else if (index > 16) {
        printf ("Grade 16+");
    }
    else {
        printf("%i\n", index) ;
    }
}

This code doesn't compile, i get these errors :

    if (i==0 ; text[i] != ' ' ||( i != len-1 && text[i] == ' ' && text[i+1] != ' '))
             ^
readability.c:27:8: note: to match this '('
    if (i==0 ; text[i] != ' ' ||( i != len-1 && text[i] == ' ' && text[i+1] != ' '))
       ^
readability.c:27:14: error: if statement has empty body [-Werror,-Wempty-body]
    if (i==0 ; text[i] != ' ' ||( i != len-1 && text[i] == ' ' && text[i+1] != ' '))
             ^
readability.c:27:14: note: put the semicolon on a separate line to silence this warning
readability.c:27:84: error: expected ';' after expression
    if (i==0 ; text[i] != ' ' ||( i != len-1 && text[i] == ' ' && text[i+1] != ' '))
                                                                                   ^
                                                                                   ;
readability.c:27:31: error: expression result unused [-Werror,-Wunused-value]
    if (i==0 ; text[i] != ' ' ||( i != len-1 && text[i] == ' ' && text[i+1] != ' '))
               ~~~~~~~~~~~~~~ ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
readability.c:27:84: error: expected expression
    if (i==0 ; text[i] != ' ' ||( i != len-1 && text[i] == ' ' && text[i+1] != ' '))
                                                                                   ^
readability.c:29:18: error: expected expression
    if (text[i]) == '.' || text[i] == '!' || text[i] == '?')
                 ^
6 errors generated.
make: *** [<builtin>: readability] Error 1 

Thank you!!

1

You can't put a semicolon inside an if condition. Use || and && to add more conditions.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .