Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.

  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 6. STRINGS AND CHARACTER ARRAYS > String Library Functions

6.7. String Library Functions

The C string library provides a large number of functions that can be used for string manipulations. The commonly used C string library functions are given in Table 6.1.

Table 6.1. C string library functions
S. NoFunction namePrototypeRole
1.strlenint strlen(const char* s);Calculates the length of a string s
2.strcpychar* strcpy(char* dest, const char* src);Copies the source string str to the destination string dest
3.strcatchar* strcat(char *dest, const char*src);Appends a copy of the string src to the end of the string dest
4.strcmpint strcmp(const char*s1, const char* s2);Compares two strings
5.strcmpiint strcmpi(const char*s1, const char* s2);Compares two strings without case sensitivity
6.strrevchar* strrev(char* s);Reverses the content of a string s
7.strlwrchar* strlwr(char* s);Converts the string to lowercase
8.struprchar* strupr(char* s);Converts the string to uppercase
9.strsetchar* strset(char* s, int ch);Set all characters in a string s to the character ch
10.strchrchar* strchr(const char* s, int c);Scans a string for the first occurrence of a given character
11.strrchrchar* strrchr(const char* s, int c);Finds the last occurrence of a character c in the string s
12.strstrchar* strstr(const char* s1, const char* s2);Finds the first occurrence of a substring (i.e. s2) in another string (i.e. s1)
13.strncpychar* strncpy(char* dest, const char* src, int n);Copies at the most n characters of the string src to the string dest
14.strncatchar* strncat(char* dest, const char* src, int n);Appends at the most n characters of the string src to the string dest
15.strncmpint strncmp(const char* s1, const char* s2, int n);Compares at the most n characters of two strings s1 and s2
16.strncmpiint strncmpi(const char* s1, const char* s2, int n);Compares at the most n characters of two strings s1 and s2 without case sensitivity
17.strnsetchar* strnset(char* s, int ch, int n);Sets the first n characters of the string s to the character ch



  

You are currently reading a PREVIEW of this book.

                                                                                                                    

Get instant access to over $1 million worth of books and videos.

  

Start a Free 10-Day Trial


  
  • Safari Books Online
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint