C program to count the words, C/C++ Programming

C program to count the words:

void CountWords();

         void main()

         {

            printf("\n\tcount the words and enter string\n\n\n");

            CountWords();

 

         }

        void CountWords()

        {

            char c;

            int num=0;

            int flag= 0;

             while((c=getchar())!='\n')

            {

                                                if((c==' ')||(c=='               ')||(c=='.')||(c==';')||(c==',')||(c==';')

                                                                ||(c==':')||(c=='"')||(c=='?')||(c=='!')||(c=='-'))

              {

                flag=0 ;       

              }                         

              else if(flag==0)

              {

                num++;

                flag=1;    

              }

 

           }

              printf("\t\n\n\nNumber of words is %d\n",num);

         }

Posted Date: 9/29/2012 7:12:05 AM | Location : United States







Related Discussions:- C program to count the words, Assignment Help, Ask Question on C program to count the words, Get Answer, Expert's Help, C program to count the words Discussions

Write discussion on C program to count the words
Your posts are moderated
Related Questions

Introduction:  This assignment requires a knowledge of variables (integers, char types), loops, conditionals, switch, functions, char arrays, string arrays, number arrays, struc

write a pseudo code for computing sin(x) using sentinel control loop


Damjibhai and Shamjibhai are two jeweler friends. They decide to play a simple game. The game comprises of removing the jewels for polishing, turn by turn. Once a jewel is removed

O v e r l o a d i n g U n a r y Op e r a t o r s Us i n g F r i e n d F u n c t i o n cl a ss s i g n { i n t a ,

Byteland county is very famous for luminous jewels. Luminous jewels are used in making beautiful necklaces. A necklace consists of various luminous jewels of particular colour. Nec

Define the Volatile Keyword Qualifiers in C Language? The volatile keyword proceed as a data type qualifier and a volatile variable is for dynamic use. E.G. for data that is to

Program to store family members details in C++: #include #include #include struct record {   char name[30];   int age;   char state[40]; }x; //cal

to calculate the amount to be paid by a customer buying yummy cupcakes for his birth day party