Online Courses
Free Tutorials  Go to Your University  Placement Preparation 
Goeduhub's Online Courses @ Udemy in Just INR 570/-
Online Training - Youtube Live Class Link
0 like 0 dislike
622 views
in JNTU BTech (CSE-I-Sem) C PROGRAMMING AND DATA STRUCTURES LAB by Goeduhub's Expert (7.1k points)

Write a C program that displays the position or index in the string S where the string T begins, or – 1 if S doesn‘t contain T.

Goeduhub's Top Online Courses @Udemy

For Indian Students- INR 570/- || For International Students- $12.99/-

S.No.

Course Name

 Coupon

1.

Tensorflow 2 & Keras:Deep Learning & Artificial Intelligence

Apply Coupon

2.

Natural Language Processing-NLP with Deep Learning in Python Apply Coupon

3.

Computer Vision OpenCV Python | YOLO| Deep Learning in Colab Apply Coupon
    More Courses

1 Answer

0 like 0 dislike
by Goeduhub's Expert (7.1k points)
edited by
 
Best answer

Sub string in Main String

In this program we are going to search for a sub string in the main string both provided by the user.

To learn string and it's function in C programming Click Here.

Example :

#include<stdio.h>
#include<string.h>
#include<conio.h>
 
void main()
{
char str[100],str1[30];
char *index;
clrscr();
 
//Entering the main string
printf("\nEnter the main first string: ");
gets(str);
 
//Entering the string whose position or index to be displayed
printf("\nEnter the string to be searched: ");
gets(str1);
 
//Searching string str1 in string str using strstr() function of C
index=strstr(str,str1);
if(index)
printf("Sub String is found in the Main String at %d position.\n",index-str+1);
else
printf("\nSub string not found");
getch();
}

Output :

Output of above program showing searching operation


For More JNTU C Programming Lab Experiments Click Here

3.3k questions

7.1k answers

393 comments

4.5k users

Related questions

 Goeduhub:

About Us | Contact Us || Terms & Conditions | Privacy Policy || Youtube Channel || Telegram Channel © goeduhub.com Social::   |  | 
...