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

CWC
0 Min Read
#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( );
}

 

Share This Article
Leave a comment

Leave a Reply

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

English
Exit mobile version