C Program to read a string and print the number of characters in each word of the string

CWC
0 Min Read
#include<stdio.h>
#include<conio.h>
#include<string.h>
main( )
{
char s[100];
int i,l,nc=0;
clrscr( );
printf(“enter the sting”);
gets(s);
l=strlen(s);
for(i=0;i<l;i++)
{
if(s[i]!=’ ‘)
{
nc=0;
while(s[i]!=’ ‘)
{
nc++;
printf(“%c”,s[i]);
i++;
if(s[i]=’\0’)
break;
}
printf(“\t\t %d”,nc);
printf(“\n”);
}} getch();
}

 

Share This Article
Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *

English
Exit mobile version