Accept a String and get Substring from it at specific position

#include<stdio.h>
#include<conio.h>
#include<string.h>

void substr(char [],int,int,char []);
void main()
{
 int s,e;
 char a[80],b[80];
 clrscr();
 printf("Enter any string\n");
 gets(a);
 printf("Enter start\n");
 fflush(stdin);
 scanf("%d",&s);
 printf("Enter end\n");
 fflush(stdin);
 scanf("%d",&e);
 substr(a,s,e,b);
 getch();
 }
void substr(char a[],int x,int y,char b[])
{
int i,j=0;
for(i=x;i<=y&&a[i]!='\0';i++)
{ b[j]=a[i];
 j++;}
 b[j]='\0';
 printf("%s",b);
 }



No comments:

Post a Comment

Related Post

Array:
String functions:
General (Loops-for/while)
Write a Program to print reverse of a given number Write a Program to print Product of Digits (eg. 212=2*1*2=4) of a given number Write a C++ Program to Convert Binary into Decimal Number