SlideShare a Scribd company logo
S1-3
Write a program in `C’ Language that accepts two strings S1 and S2 as input. The
program should check
if S2 is a substring of S1 or not. If S2 is a substring of S1, then the program
should output the
starting location and ending location of S2 in S1. If S2 appears more than once
in S1, then the
locations of all instances have to be given.
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
int i=0,j=0,v,c=0,l1,l2;
char s1[50],s2[50];
clrscr();
printf("Enter 2 strings:n");
gets(s1);
gets(s2);
l1=strlen(s1);
l2=strlen(s2);
while(i<=l1)
{
if(j==l2)
{
v=i-l2+1;
c++;
printf("Start of %d occurance=%d end =%dn",c,v,i);
j=0;
}
else if(s1[i]==s2[j])
{
i++;
j++;
}
else
{
i++;
j=0;
}
}
if(c==0)
printf("Not substring");
getch();
}
Page 1

More Related Content

What's hot (16)

PDF
Implement a queue using two stacks.
Dr. Loganathan R
 
PDF
Program in ‘C’ language to implement linear search using pointers
Dr. Loganathan R
 
PDF
Bcsl 033 data and file structures lab s1-1
Dr. Loganathan R
 
PDF
Bcsl 033 data and file structures lab s5-3
Dr. Loganathan R
 
PPTX
C Programming Example
University of Potsdam
 
PDF
C Programming Example
PRATHAMESH DESHPANDE
 
PDF
Bcsl 033 data and file structures lab s5-2
Dr. Loganathan R
 
DOCX
1 (1)
Krish Na
 
DOC
Add digits of number in c
mohdshanu
 
DOCX
Program for pyramid
nayakq
 
DOCX
Dti2143 lab sheet 9
alish sha
 
PPTX
C Programming Language Part 11
Rumman Ansari
 
Implement a queue using two stacks.
Dr. Loganathan R
 
Program in ‘C’ language to implement linear search using pointers
Dr. Loganathan R
 
Bcsl 033 data and file structures lab s1-1
Dr. Loganathan R
 
Bcsl 033 data and file structures lab s5-3
Dr. Loganathan R
 
C Programming Example
University of Potsdam
 
C Programming Example
PRATHAMESH DESHPANDE
 
Bcsl 033 data and file structures lab s5-2
Dr. Loganathan R
 
1 (1)
Krish Na
 
Add digits of number in c
mohdshanu
 
Program for pyramid
nayakq
 
Dti2143 lab sheet 9
alish sha
 
C Programming Language Part 11
Rumman Ansari
 

Viewers also liked (8)

PPT
Java intro
husnara mohammad
 
PDF
Bcsl 033 data and file structures lab s4-3
Dr. Loganathan R
 
PDF
Bcsl 033 data and file structures lab s1-2
Dr. Loganathan R
 
PPT
Academic counselling in IGNOU S.Kishore
skishoredr1
 
PPTX
IgnouBCA
diwakar9903
 
PDF
حساب المواطن السعودي الموحد الدليل الارشادي
BlackDJAttack1
 
DOCX
bank transaction system
Bhavika Pathak
 
Java intro
husnara mohammad
 
Bcsl 033 data and file structures lab s4-3
Dr. Loganathan R
 
Bcsl 033 data and file structures lab s1-2
Dr. Loganathan R
 
Academic counselling in IGNOU S.Kishore
skishoredr1
 
IgnouBCA
diwakar9903
 
حساب المواطن السعودي الموحد الدليل الارشادي
BlackDJAttack1
 
bank transaction system
Bhavika Pathak
 
Ad

More from Dr. Loganathan R (15)

PDF
Ch 6 IoT Processing Topologies and Types.pdf
Dr. Loganathan R
 
PDF
IoT Sensing and Actuation.pdf
Dr. Loganathan R
 
PDF
Ch 4 Emergence of IoT.pdf
Dr. Loganathan R
 
PPT
Introduction to Information Security
Dr. Loganathan R
 
PDF
Mcs 012 computer organisation and assemly language programming- ignou assignm...
Dr. Loganathan R
 
PDF
Session 9 4 alp to display the current system time using dos int 21 h
Dr. Loganathan R
 
PDF
Session 9 1 alp to compute a grade using procedures
Dr. Loganathan R
 
PDF
IGNOU Assembly Language Programming
Dr. Loganathan R
 
PDF
Requirement engineering process
Dr. Loganathan R
 
PDF
MCS 012 computer organisation and assembly language programming assignment…
Dr. Loganathan R
 
PDF
Software requirements
Dr. Loganathan R
 
PDF
Software process
Dr. Loganathan R
 
PDF
Software engineering critical systems
Dr. Loganathan R
 
PDF
Software engineering socio-technical systems
Dr. Loganathan R
 
PDF
Software engineering introduction
Dr. Loganathan R
 
Ch 6 IoT Processing Topologies and Types.pdf
Dr. Loganathan R
 
IoT Sensing and Actuation.pdf
Dr. Loganathan R
 
Ch 4 Emergence of IoT.pdf
Dr. Loganathan R
 
Introduction to Information Security
Dr. Loganathan R
 
Mcs 012 computer organisation and assemly language programming- ignou assignm...
Dr. Loganathan R
 
Session 9 4 alp to display the current system time using dos int 21 h
Dr. Loganathan R
 
Session 9 1 alp to compute a grade using procedures
Dr. Loganathan R
 
IGNOU Assembly Language Programming
Dr. Loganathan R
 
Requirement engineering process
Dr. Loganathan R
 
MCS 012 computer organisation and assembly language programming assignment…
Dr. Loganathan R
 
Software requirements
Dr. Loganathan R
 
Software process
Dr. Loganathan R
 
Software engineering critical systems
Dr. Loganathan R
 
Software engineering socio-technical systems
Dr. Loganathan R
 
Software engineering introduction
Dr. Loganathan R
 
Ad

Recently uploaded (20)

PPTX
Elo the Hero is an story about a young boy who became hero.
TeacherEmily1
 
PPTX
Life and Career Skills Lesson 2.pptxProtective and Risk Factors of Late Adole...
ryangabrielcatalon40
 
PPTX
MATH 8 QUARTER 1 WEEK 1 LESSON 2 PRESENTATION
JohnGuillerNestalBah1
 
PPTX
Building Powerful Agentic AI with Google ADK, MCP, RAG, and Ollama.pptx
Tamanna36
 
PDF
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
PPTX
Lesson 1 Cell (Structures, Functions, and Theory).pptx
marvinnbustamante1
 
PDF
I3PM Case study smart parking 2025 with uptoIP® and ABP
MIPLM
 
PDF
DIGESTION OF CARBOHYDRATES ,PROTEINS AND LIPIDS
raviralanaresh2
 
PDF
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.06.25.pdf
TechSoup
 
PPTX
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
PDF
AI-assisted IP-Design lecture from the MIPLM 2025
MIPLM
 
PPTX
How to Configure Taxes in Company Currency in Odoo 18 Accounting
Celine George
 
PPTX
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
PPTX
How to Add a Custom Button in Odoo 18 POS Screen
Celine George
 
PPTX
grade 8 week 2 ict.pptx. matatag grade 7
VanessaTaberlo
 
PPTX
How to Create & Manage Stages in Odoo 18 Helpdesk
Celine George
 
PPTX
Aerobic and Anaerobic respiration and CPR.pptx
Olivier Rochester
 
PDF
TLE 8 QUARTER 1 MODULE WEEK 1 MATATAG CURRICULUM
denniseraya1997
 
PDF
Cooperative wireless communications 1st Edition Yan Zhang
jsphyftmkb123
 
PDF
WATERSHED MANAGEMENT CASE STUDIES - ULUGURU MOUNTAINS AND ARVARI RIVERpdf
Ar.Asna
 
Elo the Hero is an story about a young boy who became hero.
TeacherEmily1
 
Life and Career Skills Lesson 2.pptxProtective and Risk Factors of Late Adole...
ryangabrielcatalon40
 
MATH 8 QUARTER 1 WEEK 1 LESSON 2 PRESENTATION
JohnGuillerNestalBah1
 
Building Powerful Agentic AI with Google ADK, MCP, RAG, and Ollama.pptx
Tamanna36
 
Supply Chain Security A Comprehensive Approach 1st Edition Arthur G. Arway
rxgnika452
 
Lesson 1 Cell (Structures, Functions, and Theory).pptx
marvinnbustamante1
 
I3PM Case study smart parking 2025 with uptoIP® and ABP
MIPLM
 
DIGESTION OF CARBOHYDRATES ,PROTEINS AND LIPIDS
raviralanaresh2
 
TechSoup Microsoft Copilot Nonprofit Use Cases and Live Demo - 2025.06.25.pdf
TechSoup
 
How to Manage Wins & Losses in Odoo 18 CRM
Celine George
 
AI-assisted IP-Design lecture from the MIPLM 2025
MIPLM
 
How to Configure Taxes in Company Currency in Odoo 18 Accounting
Celine George
 
How to Setup Automatic Reordering Rule in Odoo 18 Inventory
Celine George
 
How to Add a Custom Button in Odoo 18 POS Screen
Celine George
 
grade 8 week 2 ict.pptx. matatag grade 7
VanessaTaberlo
 
How to Create & Manage Stages in Odoo 18 Helpdesk
Celine George
 
Aerobic and Anaerobic respiration and CPR.pptx
Olivier Rochester
 
TLE 8 QUARTER 1 MODULE WEEK 1 MATATAG CURRICULUM
denniseraya1997
 
Cooperative wireless communications 1st Edition Yan Zhang
jsphyftmkb123
 
WATERSHED MANAGEMENT CASE STUDIES - ULUGURU MOUNTAINS AND ARVARI RIVERpdf
Ar.Asna
 

Bcsl 033 data and file structures lab s1-3

  • 1. S1-3 Write a program in `C’ Language that accepts two strings S1 and S2 as input. The program should check if S2 is a substring of S1 or not. If S2 is a substring of S1, then the program should output the starting location and ending location of S2 in S1. If S2 appears more than once in S1, then the locations of all instances have to be given. #include<stdio.h> #include<conio.h> #include<string.h> void main() { int i=0,j=0,v,c=0,l1,l2; char s1[50],s2[50]; clrscr(); printf("Enter 2 strings:n"); gets(s1); gets(s2); l1=strlen(s1); l2=strlen(s2); while(i<=l1) { if(j==l2) { v=i-l2+1; c++; printf("Start of %d occurance=%d end =%dn",c,v,i); j=0; } else if(s1[i]==s2[j]) { i++; j++; } else { i++; j=0; } } if(c==0) printf("Not substring"); getch(); } Page 1