-->

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


WAP to find initial segment of string that consists entirely of characters from second string. using strspn() function.

in turboc++
--------------------------------------------------------------------------------------------------------------
//WAP to  know location of difference of string (segment)in another string using  strspn() function.
#include <stdio.h>
#include<string.h>
#include<conio.h>
int main()
{
    char st[100],st1[100];// declaration
    printf("enter  string\n");
    gets(st);
    printf("enter second string\n");
     gets(st1);//inputs
    strspn(st,st1);
    printf("location of difference=%d\n",strspn(st,st1));//prints the location from where segment is //different
   getch();
    return 0;
}

-------------------------------------------------------------------------------------------
in codeblocks:
----------------------------------------------------------------------------------------------------------
//WAP to  know location of difference of string (segment)in another string using  strspn() function.
#include <stdio.h>
#include<string.h>
int main()
{
    char st[100],st1[100];// declaration
    printf("enter  string\n");
    gets(st);
    printf("enter second string\n");
     gets(st1);//inputs
    strspn(st,st1);
    printf("location of difference=%d\n",strspn(st,st1));//prints the location from where segment is different
    return 0;
}

WAP to set all characters in the given string to the character using strset() function.

in turboc++
----------------------------------------------------------------------------------------
//WAP to  string with other character  using(strset()) function.
#include <stdio.h>
#include<string.h>
#include<conio.h>
int main()
{
    char st[100],st1;// declaration
    printf("enter  string\n");
    gets(st);
    printf("enter a character to set for\n");
     st1=getchar();//inputs
    printf("string before setting=%s\n",st);
    strset(st,st1);
    printf("string after setting with character=%c is =%s\n",st1,st);
    getch();
    return 0;
}
-------------------------------------------------------------------------------------------
in codeblocks:
-----------------------------------------------------------------------------------------
//WAP to  string with other character  using(strset()) function.
#include <stdio.h>
#include<string.h>
int main()
{
    char st[100],st1;// declaration
    printf("enter  string\n");
    gets(st);
    printf("enter a character to set for\n");
     st1=getchar();//inputs
    printf("string before setting=%s\n",st);
    strset(st,st1);
    printf("string after setting with character=%c is =%s\n",st1,st);
    return 0;
}

wap to look for a specific character in given string using strchr() function.

in turboc++
--------------------------------------------------------------------------------------
//WAP to compare  two strings  using(strchr()) function.
#include <stdio.h>
#include<string.h>
#include<conio.h>
int main()
{
    char st[100],st1;//two string declaration
    char *p;
    printf("enter  string\n");
    gets(st);
    printf("enter a character to look for\n");
     st1=getchar();//inputs
    if(strchr(st,st1))//
    {
        p=strchr(st,st1);
        printf("strchr(st,st1)=%d\n",*p);
        printf("%c is in given string,location=%d ",st1,p-st);
    }
        else
    {
        printf("not in given character");
    }
    getch();
    return 0;
}
---------------------------------------------------------------------
in codeblocks:
---------------------------------------------------------------
//WAP to compare  two strings  using(strchr()) function.
#include <stdio.h>
#include<string.h>
int main()
{
    char st[100],st1;//two string declaration
    char *p;
    printf("enter  string\n");
    gets(st);
    printf("enter a character to look for\n");
     st1=getchar();//inputs
    if(strchr(st,st1))//
    {
        p=strchr(st,st1);
        printf("strchr(st,st1)=%d\n",*p);
        printf("%c is in given string,location=%d ",st1,p-st);
    }
        else
    {
        printf("not in given character");
    }
    return 0;
}


Write a program to sort 'n' strings. (ascending order or descending order).

in turboc++
------------------------------------------------------------------------------------
//WAP  to input some strings and sort them.
#include <stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
    char string[100][100],tempo[100];//two dimensional declaration
    int i,j,n;
    printf("enter n as total strings\n");
    scanf("%d",&n);
    printf("enter strings\n");
    for(i=0;i<=n-1;i++)
    {
        printf("string for location =%d \n",i);
        scanf("%s",string[i]);//gets inputs
    }
    printf("names and addresses are=\n");
    for(i=0;i<=n-1;i++)
    {
        printf("name =%s \n",string[i]);//prints the data .
    }
    printf("sorted strings are\n");
    for(i=0;i<=n-1;i++)
    {
        for(j=i+1;j<=n-1;j++)
        {
            if(strcmp(string[i],string[j])>0)//comparison of strings
            {
                strcpy(tempo,string[i]);
                strcpy(string[i],string[j]);//copy of string i.e. swapping of string
                strcpy(string[j],tempo);
            }
        }
    }
    printf("-------------------------------");
     for(i=0;i<=n-1;i++)
    {
        printf("name =%s \n",string[i]);//prints the data .
    }
getch();
     return 0;
}
-------------------------------------------------------------------------------------
in codeblocks:
----------------------------------------------------------------
//WAP  to input some strings and sort them.
#include <stdio.h>
#include<conio.h>
#include<string.h>
int main()
{
    char string[100][100],tempo[100];//two dimensional declaration
    int i,j,n;
    printf("enter n as total strings\n");
    scanf("%d",&n);
    printf("enter strings\n");
    for(i=0;i<=n-1;i++)
    {
        printf("string for location =%d \n",i);
        scanf("%s",string[i]);//gets inputs
    }
    printf("names and addresses are=\n");
    for(i=0;i<=n-1;i++)
    {
        printf("name =%s \n",string[i]);//prints the data .
    }
    printf("sorted strings are\n");
    for(i=0;i<=n-1;i++)
    {
        for(j=i+1;j<=n-1;j++)
        {
            if(strcmp(string[i],string[j])>0)//comparison of strings
            {
                strcpy(tempo,string[i]);
                strcpy(string[i],string[j]);//copy of string i.e. swapping of string
                strcpy(string[j],tempo);
            }
        }
    }
    printf("-------------------------------");
     for(i=0;i<=n-1;i++)
    {
        printf("name =%s \n",string[i]);//prints the data .
    }
getch();
     return 0;
}

WAP to count total number of consonants in a sting.

in turboc++
---------------------------------------------------------------------------------------------
//program to count total consonants in a string.
#include <stdio.h>
#include<conio.h>
int main()
{
    char string[100],sec;
    int i,total_consonants=0;       //initialization
    printf("enter string\n");
    gets(string);//accepts string
    strlwr(string);//converts the string into lowercase
    for(i=0;string[i]!='\0';i++)//loop execution till null character
    {
        if((string[i]>=65 && string[i]<=90)|| (string[i]>=97 && string[i]<=122)) { if(string[i])!='a' || string[i])!='e' || string[i])!='i' || string[i])!='o' || string[i])!='u') { total_consonants++; }
    }
    printf("total consonants=%d",total_consonants);// prints total consonants.
    getch();
    return 0;
}
---------------------------------------------------------------------------------------------------------------------
in codeblocks:
-----------------------------------------------------------------------------------------------
//program to count total consonants in a string.
#include <stdio.h>
int main()
{
    char string[100],sec;
    int i,count=0;       //initialization
    printf("enter string\n");
    gets(string);//accepts string
    strlwr(string);//converts the string into lowercase
    for(i=0;string[i]!='\0';i++)//loop execution till null character
    {
         if((string[i]>=65 && string[i]<=90)|| (string[i]>=97 && string[i]<=122)) { if(string[i])!='a' || string[i])!='e' || string[i])!='i' || string[i])!='o' || string[i])!='u') { total_consonants++; }
    }
    printf("total consonants=%d",total_consonants);// prints total consonants.
    return 0;
}


WAP to count total number of vowels in a string.

in turboc++
--------------------------------------------------------------------------------------
//program to count total vowels in a string.
#include <stdio.h>
#include<string.h>
#include<conio.h>
int main()
{
    char string[100],sec;
    int i,count=0;       //initialization
    printf("enter string\n");
    gets(string);//accepts string
    strlwr(string);//converts the string into lowercase
    for(i=0;string[i]!='\0';i++)//loop execution till null character
    {
        if(string[i]=='a' || string[i]=='e'|| string[i]=='i'|| string[i]=='o' ||string[i]=='u')
                                            //condition testing for character/vowels
        {
            count++;//counting  words
        }
    }
    printf("total vowels=%d",count);// prints total vowels.
    getch();
    return 0;
}

----------------------------------------------------------------------------------
in codeblocks:
---------------------------------------------------------------------------------------------------------------
//program to count total vowels in a string.
#include <stdio.h>
#include<string.h>
int main()
{
    char string[100],sec;
    int i,count=0;       //initialization
    printf("enter string\n");
    gets(string);//accepts string
    strlwr(string);//converts the string into lowercase
    for(i=0;string[i]!='\0';i++)//loop execution till null character
    {
        if(string[i]=='a' || string[i]=='e'|| string[i]=='i'|| string[i]=='o' ||string[i]=='u')
                                            //condition testing for character/vowels
        {
            count++;//counting  words
        }
    }
    printf("total vowels=%d",count);// prints total vowels.
    return 0;
}