Tuesday, October 5, 2010

Convert first character of each word ina string in upper case


/*******************************
*    Program to convert each word's   *
*    first character into upper case      *
********************************/
#include<
#include
void main()
{
    int k=1,i=0;
    char str[100];
    clrscr();
    printf("enter any string");
    gets(str);
    while(str[i]!='\0')
    {
        if(k>0)
        {
            str[i]=str[i]-32;
            k=0;
        }
        if(str[i]==' ')
        {
            k=1;
        }
        i++;
    }
    puts(str);
    getch();

}

Sunday, October 3, 2010

Replace the with a


/********************************
*         program to replace the               *
*                    with a                                *
*********************************/
#include
#include
void main()
{
    int n,i,j,m;
    char str[50];
    clrscr();
    printf("enter any string");
    gets(str);
    i=0;
    while(str[i]!='\0')
    {
        if((str[i]==' ' || i==0) && str[i]=='t' && str[i+1]=='h' && str[i+2]=='e'&& ( str[i+3]==' ' || str[i+3]=='\0') )
        {
            str[i]='a';
            n=i;
            j=++i;
            m=i+2;
            while(str[j]!='\0')
            {
                str[j]=str[m];
                j++;
                m++;
            }
            i=n;
        }

        i++;
    }
    puts(str);
    getch();

}



Cheack th position of a word in a strig

/****************************************
*                Program to find the location                *
*                of a word in a given string                   *
*****************************************/
#include
#include
void main(void)
{
    int i,j,k=0,len=0;
    char str[50],str1[20];
    clrscr();
    printf("enter the string");
    gets(str);
    printf("enter the string u wan to search");
    gets(str1);
    i=0;
    while(str[i]!='\0')
    {
        len++;
        i++;
    }
    i=0;
    j=0;
    while(j
    {
        if(str[j]==str[i])
        {
            j++;
        }
        else
        {
            j=0;
        }
        if(str[i]==' ')
        {
            k++;
        }
        i++;
    }
    if(j==len)
    {
        printf("string is present at**>%d location",k);
    }
    getch();

}