and output the number of wordsin the line and the number of occurences of each letter:?:

say the is stored in a array of char say str[], knw find the length of the string say len.
kow u have to count no. of words. a word will always start with a space( ' ' ), so start with taking a variable say flag which will monitor the occurence of spaces. for that u have to set flag as 0 first when you encounter another space then set flag to 1 u now that a word is just passed away, so increment the word counter by 1 and again set flag to 0. keep on till u encounter '\0' charecter.

for different charecters, u have to take an array of type int and size 26(A-Z), now assume array[0]='A', array[1]='B', array[2]='C'.....array[25]='Z', and now loop through str to count each character by putting this logic

for(j=0;j<len;j++)
{
 for(i=0;i<26;i++)
 {
  if(str[j]==char(65+i))
   arry[i]++;
 }
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.