Program to read a string and print the number of characters in each word of the string - 100 Most Important C# Programs

100 Most Important C# Programs

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

Code:

#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();

}