Pages

Tuesday, 30 June 2020

Substring program without library function | C Language

Q : Write a ‘C’ Program to find substring of string without using Library Function.

Answer :

#include<stdio.h>
#include<conio.h>
#define MAX 50
/*============================
     Girfa Student Help
     Substring wihout using library function
==============================*/

void main()
{
     char str[100];
     int len,i,start,end;
     clrscr();
     printf("Enter String>> ");
     scanf("%[^\n]",str);
     /* get len */
     for(len=0;str[len]!='\0';len++);
     printf("Enter start point>> ");
     scanf("%d",&start);
     printf("Enter end point>> ");
     scanf("%d",&end);
     if(start>end)
           puts("Invalid input. start is greater than end index");
     else if(end>len)
           puts("End index is greater than string length");
     else
     {
           for(start--;start<end;start++)
           {
                printf("%c",str[start]);
           }
     }
     getch();
}





No comments:

Post a Comment