0

I've been trying to compile this code but always get this error "error: expected identifier or '(' " for the line 13 (which is the first one starting with "for")

COuld someone help me?

Thanks

Here's my code:

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

int main(void) {

int letter; int countcharacters(char input);} int counter=0;

for (int i=0 ; i <= strlen (input); i++){
    letter = input[i];
    
    if (letter >= 'a' && letter <= 'z')
    {
        counter++;
        
    }
    {
        if (letter >= 'A' && letter <= 'Z'){
            counter ++;
        }
    }
    
    {
   return counter; 
}

int char letter; countWords (char input){
    int counter= 1;
    
    for (int i=0 ; i <= strlen (input); i++){
        letter = input[i];
        
        if(letter==' '){
            counter++;
        }
    }
    
    {
    return counter++;
}

int countsentences (char input){
    loop string (counter =0)
    if (letter == '.'|| letter == '!' || letter == '?')
    counter++;
    {
        return counter;
    }
}
 int index = 0.0588 * (100 * (float) countcharacters / (float) countWords) - 0.296 * (100 * (float) countsentences / (float) countWords) - 15.8;
if (index < 16 && index >= 0)
{
    printf("Grade %i\n", (int) round(index));
}

    else if (index >= 16)
{
    printf("Grade 16+\n");
}
     else
{
    printf("Before Grade 1\n");
}

printf ("Text: ");
char input[400];

fgets(input, 399, stdin);

int letters = countcharacters (input);
int words = countWords (input);
int sentences = countsentences (input);

printf("%d letter(s)", letters);
printf("%d word(s)", words);
printf("%d sentence(s)", sentences);

}

1 Answer 1

1

The problem lies here:

int letter; int countcharacters(char input);}

That closing curly brace pairs with the one that opens main(). The compiler sees this as the end of the main program and is expecting a function signature to follow.

Hint: If you highlight a curly brace in the IDE, it will also highlight the other curly brace that it pairs with.

You also have some unnecessary curly brace pairs in your code that serve no real purpose and can be removed.

If you clean up the spacing and the placement of code, it will help you find some of these issues. Try running your code through style50 until you become more proficient.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

1
  • Implement the correction that @Cliff B pointed out. Also, following the CS50 style guidelines will save you from a lot of troubles.
    – EddyBeor
    Dec 9, 2020 at 21:04

You must log in to answer this question.

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