C program to count number of word in string using while loop. / लूप का उपयोग करके स्ट्रिंग में शब्द की संख्या की गणना करने के लिए सी प्रोग्राम।












C program to count number of word in string using while loop.




C program to count number of word in string using while loop.



#include <stdio.h> #define MAX 100 int main() { char text[MAX]; int i, words; printf("\n Enter any string: "); gets(text); i = 0; words = 1; while(text[i] != '\0') { if(text[i]==' ' || text[i]=='\n' || text[i]=='\t') { words++; } i++; } printf("\n Number of words in the enter string = %d", words); return 0; }


Output:
Enter any string: C program to count number of word in string Number of words in the enter string = 9
  • Write a C program to count total number of words in a string.





  • Exercise: 1
    C program to count total number of vowels and consonants in a string.