I am suppose to create a program that counts the number of alphabets in string, words in a string and the lenght of the string and print them out! I have some code but I'm not sure how to get the string counted.
Can anyone please offer some help?
I pretty much have the basics I just need help counting the alphabets and finding out how to count the length and words that appear more than once!
#include<stdio.h>
#include<ctype.h>
#include<stdlib.h>
#include<string.h>
main() {
char sentence[35];
char *letter[26] = {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j"
"k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w" "x", "y", "z"};
int num[26] = {0};
printf("\nEnter a sentence or phrase\n");
scanf("%s", &sentence);
// loop to find alphabet characters and count each
for(int j=1; j<=26; j++) {
if(strchr(sentence, *letter[j]) != NULL) {
++num[*letter[j]];
printf("\'%c\' was found in \"%s\" %d times. \n",*letter[j], sentence, num[j]);
}
}
}