strdup duplicates the string strlwr converts string to lowercase strncat

Strdup duplicates the string strlwr converts string

This preview shows page 16 - 26 out of 34 pages.

strdup() duplicates the string strlwr() converts string to lowercase strncat() appends a portion of string to another strncpy() copies given number of characters of one string to another strrchr() last occurrence of given character in a string is found strrev() reverses the given string strset() sets all character in a string to given character strupr() converts string to uppercase strtok() tokenizing given string using delimiter
Image of page 16
©LPU CSE101 C Programming String Handling Library Functions defined in #include<string.h> String handling library provides many useful functions: Manipulate string data(copy and concatenate) Comparing strings Determine string length Search strings
Image of page 17
©LPU CSE101 C Programming String Manipulation Functions List of string manipulation functions Function prototype Function description char * strcpy ( char *s1, const char *s2 ) Copies string s2 into array s1. The value of s1 is returned. char * strncpy ( char *s1, const char *s2, int n ) Copies at most n characters of string s2 into array s1. The value of s1 is returned. char * strcat ( char *s1, const char *s2 ) Appends string s2 to array s1. The first character of s2 overwrites the terminating null character of s1. The value of s1 is returned. char * strncat ( char *s1, const char *s2, int n ) Appends at most n characters of string s2 to array s1. The first character of s2 overwrites the terminating null character of s1. The value of s1 is returned.
Image of page 18
©LPU CSE101 C Programming strcpy() and strncpy() strcpy() copies the entire second argument string into first argument. strcpy ( s1, s2); strncpy() copies the first n characters of second string argument into first string argument. strncpy ( s1, s2, 4); A null character ('\0') is appended explicitly to first argument, because the call to strncpy in the program does not write a terminating null character. The third argument is less than the string length of the second argument.
Image of page 19
©LPU CSE101 C Programming Example Code This program demonstrates string manipulation / processing functions: strcpy() and strncpy()
Image of page 20
©LPU CSE101 C Programming Output The string in array x is: Happy Birthday to You The string in array y is: Happy Birthday to You The string in array z is: Happy Birthday
Image of page 21
©LPU CSE101 C Programming strcat() Function strcat appends its second argument string to its first argument string. strcat ( s1, s2); The array used to store the first string should be large enough to store the first string the second string and the terminating null character copied from the second string. Quick yak: Ask the students to work with f_name, l_name arrays of their names using Strcat()
Image of page 22
©LPU CSE101 C Programming strncat() Function strncat appends a specified number of characters from the second string to the first string. strncat ( s1, s2, 6) A terminating null character is automatically appended to the result.
Image of page 23
©LPU CSE101 C Programming Example Code This program demonstrates string manipulation / processing functions: strcat() and strncat()
Image of page 24
©LPU CSE101 C Programming output s1 = Happy s2 = New Year strcat( s1, s2 ) = Happy New Year
Image of page 25
Image of page 26

You've reached the end of your free preview.

Want to read all 34 pages?

  • Spring '20
  • ASCII, char array

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture