0

I can't get to compile the readability program second part, that is counting the letters and outputting an integer. I've tried everything. I'm not asking for a solution, but for a hint at what my undoing is here. Thank you.

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

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

char n = '\0';

int count_letters;

for(int i = 0; i > 0; i++)

return
printf("%i \n", n);

{   while
    (count_letters (isalpha));
}
}

2 Answers 2

1

I am unfamiliar with the exact problem you are working on, but one thing I see right away is that your for loop doesn't go anywhere - you say

for(int i = 0; i > 0; i++)

but then don't have anything happen under that condition. Usually it'd be

for(int i = 0; i > 0; i++)
{
    whatever you are putting in here
}

Additionally, your for loop won't work because you have i set to 0 but then have it going while i > 0, which it's not. So it will get stuck.

Hope that was helpful.

2
  • Thank you very much. As I said to our fellow coder below, I have to review the logic behind the problem. I'll have to rework on that. But thanks.
    – 333PPP
    Aug 20, 2020 at 13:44
  • 1
    Oh, somehow I hadn't seen that answer. Good luck!
    – user29490
    Aug 21, 2020 at 2:46
1

First, there's no semicolon after return. But, that's a moot point. The return statement will cause the program to terminate immediately. It needs to be the last line in the program, before the last closing curly brace.

Next, the while loop is fatally flawed and the compiler can't make heads or tails of it. This is what's there:

{   while
    (count_letters (isalpha));
}

The correct structure of a while loop is this:

while (some_test_goes_here)
{
    //code to do in the loop goes between curly braces
}

In both cases, note the placement of the curly braces and how they are different.

This should help you along. Happy coding! ;-)

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

1
  • Thank you very much. I ordered the code as per your suggestion, but it still keeps returning errors. I think something in the logic beyond syntax is what's wrong here. I don't know what to put in "some_text_goes_here" for instance. But thank you very much for responding.
    – 333PPP
    Aug 20, 2020 at 13:38

You must log in to answer this question.

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