Introduction
Starting your question off with "My Code doesnt pass a check50 test" is NOT a good way to ask a question, approach the problem or get help.
Googling and changing your function randomly wont help you. What are you googling? The object is to learn to program/learn computer science not "to simply get the answer to this question and pass the level". So what are you googling for? googling for the answer breaks the honor code and defeats the point of the whole exercise. You have to know what's wrong to search and also know whats wrong before you change your code; and you don't know what is wrong other than that the final answer is wrong.
You need to apply the scientific method here and break it down. Figure out which method isn't working and then figure out why it isn't working and fix that method until it works. If you know that each of your count
functions is working properly then the only possibility would be your combination of them into the index generation. However I can confirm that part is correct. The problem is your count functions. But you haven't communicated or demonstrated what you have done to verify that they are working. An approach of just googling and trying to change a single function (seemingly randomly) is like searching for a needle in a haystack only worse, you could be in the wrong haystack entirely. You need to know what to ask. You need to break the problem into smaller problems and make sure each subproblem is solved properly.
Test your code
There is sample data provided see "How To Test Your Code" section. Run your program on the sample data and possibly print out for each run the number of letters, sentences and words, in addition to the final grade and verify that they are correct. That should show you which function has a problem. and give you something to work with. check50 should not be your first and only attempt at testing
That said here are some things I found to help you.
Instead of doing for loops bound by condition of
text[i] != '\0'
just use ai < strlen(text)
check like you used incountWord
in your other functions. This is a minor thing that won't change overall correctness but is a good practice.countSentence
is broken. Two problems. Your starting value ofis_sentence
. How many sentences are there if the first character is a.
or if the whole string is...
? Additionally your condition is wrong,:
does not delineate a sentence according to the instructions.Your
countWord
function is broken. The instructions literally tell you as an example thatsister-in-law
should be counted as one word, you count it as three. You are simply asking if the prior character wasn't a letter, is that sufficient? (yes the check fori == 0
before your lookback is indeed correct). you also define but don't useis_word
.
If this answers your question, please click on the check mark to accept it. Please consider upvoting the answer as well if it was useful. This helps with site maintenance.