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

100 Most Important C# Programs

83. Program to read a string and print the first two characters of each word in the string.

Code:

#include<stdio.h>

#include<conio.h>

main( )

{

char s[100];

int i,l;

clrscr( );

printf(“enter a string”);

gets(s);l=strlen(s);

for(i=0;i<l;i++)

{

if(s[i]!=’ ‘ && s[i]=’ ‘)

{

printf(“%c %c”,s[i],s[i+1])

i=i+2;

while(s[i]!=’ ‘)

i++;

}}

getch( );

}