I am right with other string but this one=>

Alice was beginning to get very tired of sitting by her sister on the bank, and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, "and what is the use of a book," thought Alice "without pictures or conversation?"

My result is grade: 7. but the answer is grade 8.


int splitword(char* inputchar){

  char * pot;

  char* tempchar = malloc(sizeof(inputchar));

  char * temp1 = tempchar;

  pot = strtok(temp1," ,.");

  int totalwords=0;

      totalwords ++;
      pot = strtok(NULL," ,.");

  return totalwords;


int splitsentence(char* inputchar){

  //Total Sentence

  int totalsentence = 0;

  char* tempchar = malloc(sizeof(inputchar));

  char * pot1 = strtok(tempchar,".!?");

     // printf("%s \n",pot);

      totalsentence ++;
      pot1 = strtok(NULL,".!?");


  return totalsentence;


int countchar(char* inputchar){

  int count=0;

  for(int i=0;i<strlen(inputchar);i++){

      int asciino = (int)inputchar[i];

      if((inputchar[i]>='a' && inputchar[i]<='z')  || (inputchar[i]>='A' && inputchar[i]<='Z')){



  return count;

int main(){

    char* inputchar = get_string("Text : ");

    int word = splitword(inputchar);

    int sentence = splitsentence(inputchar);

    int letter = countchar(inputchar);

    //float L =  (float)(letter/word)*100;
    //float S =  (float)(sentence/word)*100;

    float L =  ((float)letter/(float)word)*100;
    float S =  ((float)sentence/(float)word)*100;

    float index = 0.0588 * L - 0.296 * S - 15.8;

    int grade = roundf(index);

      printf("Grade 16+\n");
    else if(index<1){
      printf("Before Grade 1\n");
      printf("Grade %i\n",grade);

    //printf("word : %i \n", word);
    //printf("sentence : %i \n", sentence);
    //printf("letter : %i \n", letter);
    //printf("Total L :%f\n",L);
    //printf("Total S :%f\n",S);

    return 0;

Grade 7

word: 58

sentence: 2

letter: 235



What is wrong in there?


I count 57 words in one very long sentence.

By the task description, it's really just counting spaces (plus one), and counting sentence end marks. strtok here is overkill.

  • Your program should count the number of letters, words, and sentences in the text. You may assume that a letter is any lowercase character from a to z or any uppercase character from A to Z, any sequence of characters separated by spaces should count as a word, and that any occurrence of a period, exclamation point, or question mark indicates the end of a sentence.

You must log in to answer this question.

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