STRING FUNCTIONS


Function is a part of a program intended to do a certain task and located separately from the program that called it. Function is the key element in C + + because C + + language itself is formed from a collection of functions main (). A function contains statements that are packed in a name then this name can be invoked several times in several places in the program.
The purpose of making the function is:
  • Facilitate the development program. In case this is key in making a structured program.
  • Reduce the size of the program. This benefit is felt that there are several rows of the same instructions used in several places in the program.
Some library functions in C + +
Operating function string (stored in the header file "string.h")
  • Strcmp ()
    Function to copy a string of origin to the destination string variable.
    The general form: strcpy (var_tujuan, string_asal);
  • Strlen ()
    Function to obtain the number of characters from a string.
    The general form: strlen (destination, source);
  • Strupr ()
    Used to convert each letter of a string into capital letters.
    The general form: strlupr (string);
  • strcmp ()
    Used to compare two strings.
    The results of this function is of type integer with a value:
    Negative, if the first string is less than the second string.
    Zero, if the first string with second string
    Positive, if the first string is greater than the second string
    The general form: strcmp (string1, string2);
Here is a sample program using string functions above, please understand,

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

int main () {

    char x [20];
    char y [20];

    court <<"\ t \ tSlamet Islan Al Hidayah" <<endl;
    court <<"\ t \ t 10018075" <<endl;
    court <<endl;
    court <<"String Functions" <<endl;
    court <<endl;
    court <<"Input word x:";
    cin>> x;
    court <<"Input word y:";
    cin>> y;
    court <<endl;
    court <<"The number of letters x =" <<strlen (x) <<endl;
    court <<"The number of letters y =" <<strlen (y) <<endl;
    court <<endl;
    court <<"Changing so small letters of the word x =" <<strlwr (x) <<endl;
    court <<"Changing so big letters of the word x =" <<strupr (x) <<endl;
    court <<"Changing so small letters of the word y =" <<strlwr (y) <<endl;
    court <<"Changing the font so big from the word y =" <<strupr (y) <<endl;
    court <<endl;
    court <<"Combining the words x + y =" <<strcat (x, y) <<endl;
    court <<"Copying the word y =" <<strcpy (x, y) <<endl;

getch;
return 0;
}
Output :

Well that's the program that I can make,,,,,!
If there are less jelass know any mistake, do not hesitate to leave a comment ataun advice. So that I can fix it later terimakasihh over his visit,,
Regards super ..




0 Response to " STRING FUNCTIONS "