String Manipulations In C Programming Using Library Functions

C Flow Control?

In this tutorial, you will learn about if statement (including if...else and nested if..else) in C programming with the help of examples.

C Functions?

In this tutorial, you will be introduced to functions (both user-defined and standard library functions) in C programming. Also, you will learn why functions are used in programming.

C Programming Arrays?

In this tutorial, you will learn to work with arrays. You will learn to declare, initialize and access elements of an array with the help of examples.

C Programming Pointers?

In this tutorial, you'll learn about pointers; what pointers are, how do you use them and the common mistakes you might face when working with them with the help of examples.

C Programming Strings?

In this tutorial, you'll learn about strings in C programming. You'll learn to declare them, initialize them and use them for various I/O operations with the help of examples.

Structure And Union?

In this tutorial, you'll learn about struct types in C Programming. You will learn to define and use structures with the help of examples.

C Programming Files?

In this tutorial, you will learn about file handling in C. You will learn to handle standard I/O in C using fprintf(), fscanf(), fread(), fwrite(), fseek() etc. with the help of examples.

Additional Topics?

In this tutorial, you will learn about enum (enumeration) in C programming with the help of examples.
String Manipulations In C Programming Using Library Functions

String Manipulations In C Programming Using Library Functions

In this article, you’ll learn to manipulate strings in C using library functions such as gets(), puts, strlen() and more. You’ll learn to get string from the user and perform operations on the string.

 

You need to often manipulate strings according to the need of a problem. Most, if not all, of the time string manipulation can be done manually but, this makes programming complex and large.

To solve this, C supports a large number of string handling functions in the standard library "string.h".

Few commonly used string handling functions are discussed below:

Function Work of Function
strlen() computes string’s length
strcpy() copies a string to another
strcat() concatenates(joins) two strings
strcmp() compares two strings
strlwr() converts string to lowercase
strupr() converts string to uppercase

Strings handling functions are defined under "string.h" header file.

#include <string.h>

Note: You have to include the code below to run string handling functions.

gets() and puts()

 

 
 

Functions gets() and puts() are two string functions to take string input from the user and display it respectively as mentioned in the previous chapter.

#include<stdio.h>

int main()
{
    char name[30];
    printf("Enter name: ");
    gets(name);     //Function to read string from user.
    printf("Name: ");
    puts(name);    //Function to display string.
    return 0;
}

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

Previous Tutorial:
C Programming String
Next Tutorial:
C String Examples