Here is my code so far:
#include <stdio.h> #include <string.h> #include <ctype.h> #define SENTENCE 256 int main(void){ char my_sen[SENTENCE], *s; //String that containts at most 256 as well as a pointer int words = 1, count = 0,vowel_word = 0; //Integer variables being defined int i,vowel = 0, length; //More definitions printf("Enter a sentence: ");//Input sentence gets(my_sen);//Receives and processes input length = strlen(my_sen); //Stores the length of the input within length for(i=0;my_sen[i] != '\0'; i++){ if(my_sen[i]=='a' || my_sen[i]=='e' || my_sen[i]=='i' || my_sen[i]=='o' || my_sen[i]=='u' || //Loop that states if the input contains any of the following my_sen[i]=='A' || my_sen[i]=='E' || my_sen[i]=='I' || my_sen[i]=='O' || my_sen[i]=='U') //characters(in this case, vowels), then it shall be { //stored to be later printed vowel++; } if(my_sen[i]==' ' || my_sen[i]=='!' || my_sen[i]=='.' || my_sen[i]==',' || my_sen[i]==';' || //Similar to the vowel loop, but this time my_sen[i]=='?') //if the following characters are scanned within the input { //then the length of the characters within the input is length--; //subtracted } } for(s = my_sen; *s != '\0'; s++){ //Loop that stores the number of words typed after if(*s == ' '){ //each following space count++; } } printf("The sentence entered is %u characters long.\n", length); //Simply prints the number of characters within the input printf("Number of words in the sentence: %d\n", count + 1); // Adding 1 to t[he count to keep track of the last word printf("Average length of a word in the input: %d\n", length/count);//Prints the average length of words in the input printf("Total Number of Vowels: %d\n", vowel);//Prints the number of vowels in the input printf("Average number of vowels: %d\n", vowel/count);//Prints the average number of vowels within the input return 0; }
How do I manage getting around to checking if any words are palindromes or not? And how can I implement this into
int is_palindrome(char my_sen[])and still call upon it in main?