C program to split sentence for a given character - My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Thursday, January 30, 2020

C program to split sentence for a given character - My CS Tutorial

Program for splitting sentence for a character.
In this tutorial we will learn how to write a c program to split sentence for a given character.

In the first user will enter a string by using keyboard and enter a character then the compiler split that sentence or string and show the sentence in two parts as:-

SENTENCE IS:-

HC78326@GMAIL.COM

AND GIVEN CHARACTER IS:- @

THEN THE SPLITTING SENTENCE IS

HC78326
GMAIL.COM


C PROGRAM CODE



#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
    int x=0,y=0,z=0;
    char st1[100]={0},subst[100][100]={0},c;
 
    clrscr();
 
    printf("\n ENTER A STRING OR SENTENCE:\n ");
    gets(st1);
 
    printf("\n ENTER A CHARACTER  TO SPLIT:\n ");
    scanf("%c",&c);
 
    while(st1[z]!='\0')
    {
        y=0;
        while(st1[z]!=c&&st1[z]!='\0')
        {
            subst[x][y]=st1[z];
            z++;
            y++;
        }
        subst[x][y]='\0';
        x++;
        if(st1[z]!='\0')
        {
            z++;
        }
    }
    int len=x;
 
    printf("\n AFTER SPLITTING SENTENCE, WORDS ARE:\n");
    for(x=0;x<len;x++)
    {
        printf(" %s \n",subst[x]);
    }
    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