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.
#include<stdio.h>
#include<cs50.h>
#include<string.h>
#include<malloc.h>
#include<math.h>
int splitword(char* inputchar){
char * pot;
char* tempchar = malloc(sizeof(inputchar));
strcpy(tempchar,inputchar);
char * temp1 = tempchar;
pot = strtok(temp1," ,.");
int totalwords=0;
while(pot!=NULL)
{
//printf("%s\n",pot);
totalwords ++;
pot = strtok(NULL," ,.");
}
return totalwords;
}
int splitsentence(char* inputchar){
//Total Sentence
int totalsentence = 0;
char* tempchar = malloc(sizeof(inputchar));
strcpy(tempchar,inputchar);
char * pot1 = strtok(tempchar,".!?");
while(pot1!=NULL)
{
// 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')){
count++;
}
}
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);
if(index>16){
printf("Grade 16+\n");
}
else if(index<1){
printf("Before Grade 1\n");
}
else{
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
L:405.172394
S:3.448276
What is wrong in there?