C String Function


String.h function supports all the string functions in C.

There are commonly used string functions in C. They are

  • strcat(): it concatenates str2 at the end of str1.
  • strcmp(): it returns 0 if str1 is same as str2.
  • strcpy(): it copies str2 into str1.
  • strlen(): it gives the length of str1.
  • strncpy(): it copies given the number of characters of one string to another.
  • strchr(): it returns the pointer to the first occurence of char in str1.
  • strrchr(): The last occurrence of given character in a string is found.
  • strstr(): it returns the pointer to the first occurence of str2 in str1.
  • strdup(): it duplicates the string.
  • strlwr(): it converts the string to lowercase.
  • strupr(): it converts the string to uppercase.
  • strrev(): it reverses the given string.
  • strset(): it sets all character in a string to given character.
  • strtok(): it tokenizing given string using the delimiter.

Example:

#include <stdio.h>
#include <string.h>

void main () {
    char str1[30] = "Welcome to";
    char str2[30] = " Onlinetpoint";
    char str3[50];
    /* concatenates str1 and str2 */
    strcat( str1, str2);
	printf("String concatenate str1 & str2:   %s\n", str1 );
    /* copy str1 into str3 */
    strcpy( str3, str1);
    printf("String copy from str1 to str3:   %s\n", str3 );

}



OnlineTpoint is a website that is meant to offer basic knowledge, practice and learning materials. Though all the examples have been tested and verified, we cannot ensure the correctness or completeness of all the information on our website. All contents published on this website are subject to copyright and are owned by OnlineTpoint. By using this website, you agree that you have read and understood our Terms of Use, Cookie Policy and Privacy Policy.