You are on page 1of 3

Lab Report

On
A program that will a string as input and print the position
of the substring in the output
COURSE CODE: CSE 232
Course Title: Data Structures Lab
Experiment No - 01

Submitted To: Submitted By:


Sadah Anjum Shanto Romzan Ali Mohon

Lecturer Id: 17182103177


Intake: 38,
Dept. of CSE Section: 4

DEPARTM ENT OF CO M PUTER SCIENCE AND ENG INEERING


BANGLA DESH UNIVERSITY OF BUSINESS AND TECHNOLOGY

Submission Date: 06.05.2019


Source code:

#include <stdio.h>

int main()

char str[100], sub_str[50];

int i, j, temp = 0;

printf("enter a string: \n");

gets(str);

printf("enter the sub-string: \n");

gets(sub_str);

for(i = 0; str[i] != '\0'; i++)

j = 0;

if(str[i] == sub_str[j])

temp = i+1;

while(str[i] == sub_str[j])

i++;

j++;

if(sub_str[j] == '\0')

printf("The sub-string's position: %d\n", temp);


}

else

i = temp-1;

temp = 0;

if(temp == 0)

printf("The sub-string is not present in the main string");

return 0;

You might also like