#include <cs50.h>
#include <ctype.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
int count_sentences(string text);
int main(void)
{
string text = get_string("Text: ");
int count_sentences(string text);
{
int sentences = 1;
for (int j = 0; j < strlen(text); j++)
{
if (text[j] == '.' || text[j] == '?' || text[j] == '!')
{
sentences++;
}
}
return sentences;
}
printf("Sentences: %i\n", count_sentences);
}
I am doing the cs50 course through edx. I am stuck on a problem set in week two that has us write a program to assign a reading grade level to a user given text. I have figured out how to count the letters and words portion of the problem. However, the sentence count portion is giving me a hard time. Above is the test piece I have drafted before I implement it in my final code to make sure it functions the way I want. When I try to make the code it gives me this error:
test.c:24:31: error: format specifies type 'int' but the argument has type 'int (*)(string)' (aka 'int (*)(char *)') [-Werror,-Wformat]
24 | printf("Sentences: %i\n", count_sentences);
| ~~ ^~~~~~~~~~~~~~~
1 error generated.
make: *** [<builtin>: test] Error 1
I cannot figure out what I am doing wrong. Any advice would be greatly appreciated.
count_sentencesis a function, and should be defined outside of main (for canonical C). When you want to call it, you need to write it's name and pass the parameters it expects in parentheses.()to call the function:count_sentences()