All C&DS Needs

Tell's You Everything

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.

/* 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.
*/

#include<stdio.h>
#include<string.h>
#include<conio.h>

void main()
{
char s[30], t[20];
char *found;
clrscr();

/* Entering the main string */
puts(“Enter the first string: “);
gets(s);

/* Entering the string whose position or index to be displayed */
puts(“Enter the string to be searched: “);
gets(t);

/*Searching string t in string s */
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();
}

About these ads

One response to “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.

  1. vinay March 1, 2012 at 22:39

    thnx fr upld…..

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 32 other followers

%d bloggers like this: