Mask-group

Standard Library String Functions

Standard Library String Functions




https://lh6.googleusercontent.com/lj151LvR9NB9W7iAh-VtY_8xzBSKLXEUdvzRhBbKugFOL11l0dDk-ZolIz135ZocnSz2YqO8heTMctk7PDb7jDVo6Jv6Z1sPL-r1MW7WCZwKkN4aVVHChuiqJrY2M1KrOhPETnR7ExLh6r8oxg

strlen( ), strcpy( ), strcat( ) and strcmp( ) are the most commonly used string functions.

  1. strlen():
    1. This function counts the number of characters present in a string.
    2. Example:-


  1. strcpy():
    • This function copies the contents of one string into  another.

​​​​​​​

  • On supplying the base addresses, strcpy( ) goes on copying the characters in source string into the target string till it doesn't encounter the end of source string (‘\0’)
  1. ​​​​​​​strcat():
    • ​​​​​​​​​​​​​​This function concatenates the source string at the end of the target string.

​​​​​​​​​​​​​​​​​​​​​

  1. strcmp():

  • ​​​​​​​This is a function which compares two strings to find out whether they are the same or different. 

  • The two strings are compared character by character until there is a mismatch or end of one of the strings is reached, whichever occurs first. If the two strings are identical, strcmp( ) returns a value zero. If they’re not, it returns the numeric difference between the ASCII values of the first non-matching pairs of characters.

​​​​​​​