-->
Showing posts with label WAP to scan first string for the first occurrence of the substring in string second using strstr() function.. Show all posts
Showing posts with label WAP to scan first string for the first occurrence of the substring in string second using strstr() function.. Show all posts

WAP to scan first string for the first occurrence of the substring in string second using strstr() function.

in turboc++
-------------------------------------------------------------------------------------------------------
//program to understand strstr() function
#include <stdio.h>
#include <stdlib.h>
#include<conio.h>
int main()
{
    char name[100],string[100];
    printf("enter string\n");
    gets(name);//gets the string
    printf("enter string to be searched\n");
    gets(string);//gest the string to be searched and to be printed from.
    printf("substrig=%s\n",strstr(name,string));//prints the characters from input string
    getch();
    return 0;
}
/*
note:-
It prints the string from occurrence of first character.
e.g
abcdefg
c
it will print all the letters starting from 'c'
*/


-----------------------------------------------------------------------------
in codeblocks
--------------------------------------------------------------------------------------
//program to understand strstr() function
#include <stdio.h>
#include <stdlib.h>

int main()
{
    char name[100],string[100];
    printf("enter string\n");
    gets(name);//gets the string
    printf("enter string to be searched\n");
    gets(string);//gest the string to be searched and to be printed from.
    printf("substrig=%s\n",strstr(name,string));//prints the characters from input string
    return 0;
}
/*
note:-
It prints the string from occurrence of first character.
e.g
abcdefg
c
it will print all the letters starting from 'c'
*/