String Manipulations In C Programming Using Library Functions
Strings are often needed to be manipulated by programmer according to the need of a problem. All string manipulation can be done manually by the programmer but, this makes programming complex and large. To solve this, the C supports a large number of string handling functions.
There are numerous functions defined in
"string.h" header file. Few commonly used string handling functions are discussed below:
Strings handling functions are defined under
"string.h" header file, i.e, you have to include the code below to run string handling functions.
#include <string.h>
gets() and puts()
Functions gets() and puts() are two string functions to take string input from user and display string respectively as mentioned in 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; }
Though, gets() and
puts() function handle string, both these functions are defined in
"stdio.h" header file.