String Manipulations In C Programming
String Manipulations In C Programming: In this article, you’ll learn to manipulate strings in C using the library functions, for example, gets(), puts, strlen(), and more. You’ll learn to get a string from the user and perform the procedure on the string.
You need to manipulate strings according to the need for an issue. Most, if not all, of the time string, manipulation should be possible physically, be that as it may, this makes programming intricate and large.
To understand 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 the “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.
Please feel free to give your comment if you face any difficulty here.