Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Homework HelpRSS Feeds

Program that counts number of words in a given string......

Posted By: Easy Tutor     Category: C Programming     Views: 25246

Write a program that counts number of words in a string specified by user.

Code for Program that counts number of words in a given string...... in C Programming

#include <stdio.h>
#include <conio.h>
void main(){
     char s[50],ch;
     int i,c=0;
     clrscr();
     printf("Enter any string : ");
     for(i=0;ch!='\n';i++){
     ch=getchar();
     s[i]=ch;
     }
     s[i]='\0';

     for(i=0;s[i]!='\0';i++){
    if(s[i]==' '){
       c++;
       while(s[i]==' ')
        i++;
    }
     }
     printf("\n\nTotal words are %d",c+1);
     getch();
}
  
Share: 



Easy Tutor
Easy Tutor author of Program that counts number of words in a given string...... is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

Related Articles and Code:


 

Other Interesting Articles in C Programming:


 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!