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.

Program Code:
#include <stdio.h>
#include<string.h>
#include<conio.h>
void main()
{
char s[30], t[20];
char *found;
puts("Enter the first string: ");
gets(s);
puts("Enter the string to be searched: ");
gets(t);
found = strstr(s, t);
if(found)
{
printf("Second String is found in the First String at %d position.\n", found - s);

}
else
{
printf("-1");
}
getch();
}



Mukesh Rajput

Mukesh Rajput

I am a Computer Engineer, a small amount of the programming tips as it’s my hobby, I love to travel and meet people so little about travel, a fashion lover and love to eat food, I am investing a good time to keep the body fit so little about fitness also..

Post A Comment:

0 comments: