954,505 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

help for writing a program that'll read in a line of text

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

tan_vir
Newbie Poster
2 posts since Mar 2007
Reputation Points: 10
Solved Threads: 0
 

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]++;
 }
}
Luckychap
Posting Pro in Training
444 posts since Aug 2006
Reputation Points: 83
Solved Threads: 61
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You