CodesJava

Easy learning with example program codes

C String Functions


String Functions are the built-in functions provided by C to operate and manipulate a string. C provides a number of string functions. Some of the MOST USED string functions are listed below:

FUNCTION SYNTAX USES
strlwr() strlwr (string ) Converts a string to lowercase letters.
strupr() strupr (string ) Converts a string to uppercase letters.
strcpy() strcpy(destination, source) Copies a string from source to destination.
strcat() strcat(string1, string2) Concatenates two strings.
strcmp() strcmp(string1, string2) Compares two strings, if same, it returns 0.
strrev() strrev (string ) Reverses a string.
strlen() strlen (string name) Returns the length of a string.

Example:

#include<stdio.h>  
#include <string.h>  
#include <stdbool.h>
 
void main()
{    
char str1[10] = "Hello C. ";  
char str2[20] = "Hello World.";  
char str3[30];
bool a;
int b;
 
strcpy(str3, str2);
puts(str3);
strcat(str1, str2);
puts(str1);
a = strcmp(str1, str2);
printf ("%d\n",a);
b = strlen (str1);
printf ("%d\n",b);
}

Output

Hello World.
Hello C. Hello World.
1
21
Posted in C   
Sign Up/ Sign In
Ask a Question


Copyright © 2018 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki