2

I found that when following the instructions to create readability, the newly created tab "readability.c" has a red dot, and when clicked, it prompted me to save. Once saved, it should work. Hope this helps.


2

Pretty sure you meant isalnum. But shouldn't it be isalpha?


2

What is happening there, is that you did your word count asuming that the next caracter would be alphabetical, here: al = isalpha(text[i + 1]);, but in this case, the next caracter are quotation marks so it's not counting a couple of words.


1

You are not saving the value from your functions. What you're doing is the you call the function then the function counts the sentences and returns the count but your not assigning that return value to any variable, so it's basically doing nothing then you're passing you're functions as the arguments for the index function.


1

You have to add } at the end, and in the middle before float l = 100 / words * letters; to close out the for loop.


1

It just so happens that the memory allocated to letter_box here char *letter_box = (char*)malloc(strlen(text+1)); is all nulls (ie \0). Since the if loop will not change any non-alpha character (more or less, there is a typo in the if statement), the first \0 encountered is "end-of-string". This letter_box[i] = text[i]; is fundamentally wrong, since ...


1

The variables that you create in the for loops only exist within that for loop. You can use the result of a certain iteration of a for loop by eg: including an if function within the for loop to pick up what you are after .


1

It's a scope problem: When you declare a variable inside a 'for' loop or a function, it only will be available until the loop/function ends. For example in your for loop: for(int i=0;text[i]!='\0';i++) as 'i' is declared and inicialized at the begining of the for loop, as soon as the loop finishes, it'll be destroyed and you won't be able to access to it ...


1

Press Ctrl+S (Windows) or Command + S (MacOS) to save the file. It will let you choose which directory you want to use.


1

Have a look at your evaluation condition for your loop: i += 1, n The net result of this condition is simply that i will get incremented by 1 each loop. The comma operator has the lowest precedence so the ", n" is essentially irrelevant here. Because the loop already increments i each turn, the loop will ultimately increment i by 2 every iteration ...


1

string input = get_string("Text:"); //getting input from the user int len = strlen(input); //determining the length of the string int space = 0; //declaring a variable to count whitespaces for (int i = 0; i < len; i++) //declaring a for loop to check each element of the string { if (input[i] == ' ') { space++; ...


1

There are several problems. First, the word count is off by 1. Hint: is the code actually reading the end of string marker? Second, and most important, look at the calculations: float L = count_letters / count_words * 100; float S = count_sentences / count_words * 100; Each of the elements in the calculations is an integer. That means that this is integer ...


1

the issue is the condition you wrote inside the for loop for i (s[i] != 0 || s[i] != 1 ). you need to set a limit for i (when will the for loop terminate ? = when will the i stop increasing by 1?). otherwise i increases forever and you run out of memory , thus your seg.fault. have another look at the different types of loops (for vs if vs while) - the short ...


1

the reason that your program is not working is because you are decrementing words with each question mark and exclamation point. If you remove words--; from your program, it works correctly! By the way, the actual inputs are listed here: https://cs50.harvard.edu/x/2020/psets/2/readability/#:~:text=How%20to%20Test%20Your%20Code The test input that your ...


1

isalpha() expects a char, not a char *. You could dereference str using str[0], str[1] and so on. You can figure out which line of code is causing the segmentation fault by first clicking to the left of a line of code to set a breakpoint, running your program through debug50, then using the "step over" button at the top of the menu that comes up on ...


1

Hint: The function isalpha(), along with it's cousins like isspace() and ispunct(), etc., are your friends. ;-)


1

Syntax error. You just need to change it to the correct syntax. do { ... } while(isalpha(n)); The isalpha() function takes a parameter (inside the parentheses). That's what will be checked whether it is a letter. That will fix your compile error with isalpha. But there are still problems with the code. First, what is this about? char n = '\1'; If ...


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 (...


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 ...


1

count_letters is a function. count_letters("Some text") is an int. You've got the %i flag in your printf statement, so you need an int as the second argument. That's why it's not compiling. It won't work either, because you'll never run that line of code. The return statement on line 25 will exit that function, and line 26 will never run. (Also, ...


1

Did you notice that your code includes a colon after the word grade but check50 results don't? ;-) The lesson here is that program specs are to be followed exactly and precisely. Close or similar doesn't get it done.


1

From man ispunct: ispunct() checks for any printable character which is not a space or an alphanumeric character. This if (ispunct(txt[i])) will be true for a whole host of characters that are not ., ? or !.


1

The code doesn't work because num_letters is 0. The for loop will never run. In fact, it won't compile either because i and len are not created/defined before attempting to use them.


1

Experiencing the same issue. I've tried instructions verbatim several times and receiving "make: *** No rule to make target 'readability'. Stop I've tried deleting, and starting over, but no luck.


1

isalnum has no place here. isalpha checks for letters. Shouldn't matter as we have no digits. The word count is overcomplicated. Per problem specification, anything separated by spaces should be considered a word, and there are only single spaces, and no leading/trailing ones. So simply count the space characters (plus one), no further checks. Same for ...


1

The printf executes for every i because it is inside the for loop. If it should only execute when the for loop is complete, it needs to be outside the block (ie after the closing }).


1

First, L and S should be floating point variables, using type float or double (either would work here). Then, the computation should be using floating point division. Integer division truncates the result to be integer again (as does assigning to an integer variable), change for example 100 to 100.0 to make it a floating point division. Also, the value ...


1

Do you see anything wrong here? for (int i = 0; i > strlen(text); i++) Will this for loop ever run? Is the test valid?


1

Do you know the name of the package instead of using sent_tokenize? thanks


1

Try .split() instead. And if you need to split multiple characters use regular expressions re.split() provided with characters given in specification for readability.c in pset2.


Only top voted, non community-wiki answers of a minimum length are eligible