English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structure

C Language File

C Other

C Language Reference Manual

C Language String Functions

In this article, you will learn to use library functions such as gets(), puts, strlen() to operate strings in C. You will learn to get strings from the user and perform operations on the string.

You usually need to operate according to the needs of the problemString.Most string operations can be completed by custom methods, but this will make programming more complex and bulky.

To solve this problem, C inIn the standard library "string.h" supports a large number of string handling features.

The following discusses several commonly used string handling functions:

FunctionDescription
strlen()Calculate the length of a string
strcpy()Copy one string to another string
strcat()

Concatenate (join) two strings

strcmp()Compare two strings
strlwr()Convert a string to lowercase
strupr()Convert a string to uppercase

String handling functions are defined under the "string.h" header file.

#include<string.h>

Note:You must include the above code to run the string handling functions.

gets() and puts()

The functions gets() and puts() are two string functions used to receive the user's string input and display them respectively, such as  The previous chapter discussed.

#include<stdio.h>
int main()
{
    char name[30];
    printf("Enter name: ");
    gets(name);     //The function reads a string from the user.
    printf("Name: ");
    puts(name);    //function to display the string
    return 0;
}

Note:Although the gets() and puts() functions handle strings, both of these functions are defined in the "stdio.h" header file.