C program to find or print all words that ended by given character in a string or sentence.
In this tutorial we will learn how to write a c program to find all words ended by given character.
Character will be enter by user through the keyboard.
In this tutorial we will learn how to write a c program to find all words ended by given character.
Character will be enter by user through the keyboard.
C program code
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i,j,start=0;
char str[100],character;
clrscr();
printf("\n ENTER A STRING OR SENTENCE:\n ");
gets(str);
printf("\n");
printf("\n ENTER A CHARACTER TO FIND THE WORD:\n ");
scanf("%c",&character);
for(i=0;i<=strlen(str);i++)
{
if((str[i]==' ' && str[i-1]==character)||(str[i]=='\0' && str[i-1]==character))
{
for(j=start;j<i;j++)
{
printf("%c",str[j]);
}
printf("\n");
start=i+1;
}
else
{
if(str[i]==' ')
start=i+1;
}
}
getch();
}
OUTPUT:
Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.If you have any method of this program or want to give any suggestion send email on hc78326@gmail.com
Created by-- HARSH CHAUHAN
No comments:
Post a Comment