Counts characters and words in a string


/*This program counts the characters in a string and the words in it */
#include<stdio.h>
#include<conio.h>
int main()
{
 int count_words=0,i;
 int count_char=0;
 char str[20];
 printf("Enter string: ");
 gets(str);
 for(i=0; str[i]!=NULL; i++)
 {
   char++;
   if(str[i]==' ') /*Controlls if the character is a space*/
      words++;
 }
 printf("\nNumber of characters : %d",char);
 printf("\nNumber of words: % d",words+1);
 getch();
 return 0;
}

     Output :

Enter string : programming geek
Number of characters in string : 16

Number of words in string : 2

Comments

Popular posts from this blog

Configure IP address on Oracle Linux

Oracle Directory Object

TIME INTERVAL in Oracle