Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Bracket error in c "error: expected identifier or '(' {"

I’m working on a problem set for CS50 in C but I keep getting an error readability.c:11:1: error: expected identifier or '(' { and I’m not sure what’s wrong. Any help would be much appreciated.

#include <cs50.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>

int count_letters(string text);

int main(void);
{
    string paragraph = get_string("Input text: ");

    count_letters(paragraph);

    int L = 0;
    int S = 0;

    int index = 0.0588 * L - 0.296 * S - 15.8;

    printf("%i", index);
}

int count_letters(string text)
{
    int letters = 0;

    for (int i = 0, length = strlen(text); i < length; i++)
        if isalpha(text[i]) {
            letters + 1
        }

    return letters;
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You have a semicolon at

int main(void);

and you need one here:

for (int i = 0, length = strlen(text); i < length; i++){ //added {
  if(!(isalpha(text[i]) == 0)){ // is alpha in brackets too and I usually prefer to check result with proper types
    letters + 1; //addded ;
  }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading