Proxy > Gmail Facebook Yahoo!

How String Functions Work? in C++ Part -2



mystrlwr():

  // mystrlwr function
  #include<iostream.h>

  // -- FUNCTION PROTOTYPES --
  char *mystrlwr(char *);
  // --       ENDS          --

  void main()
  {
    char ch[]="C++ ProGramming123";

    cout<<mystrlwr(ch);
  }

  char *mystrlwr(char *str)
  {
    char *temp;
    temp=str;

    while(*str!='\0')
    {
      // change only if its a
      // UPPER case character
      // intelligent enough not to
      // temper with special 
      // symbols and numbers
      if(*str>=65 && *str<=90)
        *str+=32;
      str++;
    }
    return temp;;
  }
mystrupr():

  // mystrupr function
  #include<iostream.h>

  // -- FUNCTION PROTOTYPES --
  char *mystrupr(char *);
  // --       ENDS          --

  void main()
  {
    char ch[]="C++ ProGramming123";

    cout<<mystrupr(ch);
  }

  char *mystrupr(char *str)
  {
    char *temp;
    temp=str;

    while(*str!='\0')
    {
      // change only if its a
      // UPPER case character
      // intelligent enough not to
      // temper with special 
      // symbols and numbers
      if(*str>=97 && *str<=122)
        *str-=32;

      str++;
    }
    return temp;
  }
mystrncat():

  // mystrncat- function 
  #include<iostream.h>

  void mystrncat(char *,const char *,int);

  void main(void)
  {
    char ch[]="This is great!";
    char ch2[25]="Yes ";
    mystrncat(ch2,ch,6);

    cout<<ch;
    cout<<endl;
    cout<<ch2;
  }

  void mystrncat(char *str1,const char *str2,int n)
  {
    int i=0;
    int len=0;

    // skip to the end of the first
    // string(target)
    while(str1[len]!='\0')
      len++;

    // start copying 'n' characters
    // from the start of the 
    // second string (source)
    // to the end of the
    // first (target)
    while(i<n)
    {
      str1[len]=str2[i];
      i++;len++;
    }
    str1[len]='\0';
  }
mystrncpy():

  // mystrncpy- function 
  #include<iostream.h>

  void mystrncpy(char *,const char *,int);

  void main(void)
  {
    char ch[]="This is great!";
    char ch2[20];

    mystrncpy(ch2,ch,6);

    cout<<ch;
    cout<<endl;
    cout<<ch2;
  }

  void mystrncpy(char *str1,const char *str2,int n)
  {
    int i=0;

    // copy 'n' characters
    // from str2 to str1
    while(i<n)
    {
      str1[i]=str2[i];
      i++;
    }
    // put the end of 
    // string identifier
    str1[i]='\0';
  }
mystrrev():

  // mysrtrev function

  #include<iostream.h>

  char *mystrrev(char *);

  void main(void)
  {
    char ch[]="Programming";
    cout<<mystrrev(ch);

    cout<<ch;
  }

  char *mystrrev(char *str)
  {
    char temp;
    int len=0;
    int i,j;

    // find the length
    while(str[len]!='\0')
      len++;

    j=len-1;

    for(i=0;i<len/2;i++)
    {
      // interchange the
      // characters from
      // the beginning to 
      // the end
      temp=str[j];
      str[j]=str[i];
      str[i]=temp;
      j--;
    }

    return str;
  }


Responses

0 Respones to "How String Functions Work? in C++ Part -2"


Send mail to your Friends.  

Expert Feed

 
Return to top of page Copyright © 2011 | My Code Logic Designed by Suneel Kumar