C Programming Examples On Strings
C Programming Examples On Strings
This section covers C programming examples on String Operations. Every example program includes
the description of the program, C code as well as output of the program. All examples are compiled
and tested on a Linux system. These examples can be simple C programs or advanced C programs.
So, they are suitable for any user (dummies, beginners or advanced users).
Here is the listing of C programming examples on String Operations.
1. C Examples on Palindrome
A palindrome is a sequence of characters which reads the same from left to right and right to left.
There are many methods to check if a given string is Palindrome. They are 1) using recursion and 2)
without using a built-in function. The following section contains C programs which check if the given
string is a Palindrome using the methods mentioned above and one more program in the section prints
the smallest and the largest possible word from the string which is a palindrome and also in a string
which is not a palindrome.
The following section contains programs which deal with performing operations on a string. These
operations include Concatenation and Comparison. The process of joining two strings end-to-end is
called Concatenation. The process of comparing the contents of two strings for their equality is called
Comparison. The section contains programs which illustrate the above operations. A portion of the
given string is called substring. There are also programs in the section which check if the given string
contains a substring and finds the length of the string without using a built-in function.
The repetition of the characters in a string is called Frequency. The following section contains C
Programs which finds the frequency of the word the in a given sentence, finds the number of times
the substring occurs in the given string, to find the frequency of every word in a given string and to find
the highest frequency character in a string. The section also illustrates the use of copy function which
copies one string to another using recursion and a program which reads a given string and finds the
sum of all the digits in a string. Then we have programs which use the concept of recursion. These
programs include a program to find the first capital letter in a string using recursion and a program to
find the string length using recursion. Other programs in this section include a program to find the
repeating sequence that is the longer, program to find the length of the longest repeating sequence in
a string and a program to find all the possible subsets of a string.
An anagram is the process of finding a new word by rearranging the original letters of the word. The
program in the following section checks if the two given strings are anagrams. The remaining programs
in the section deal with listing, displaying, inserting and printing the characters or the words. It has
programs to display the possible combination of 3 strings from the given strings without any repetitions,
program to list all the lines contained in the given string, a program to print the all the possible words
ending with the letter S and a program to insert character/word in a desired location in a string.
The following section contains C programs that implement certain functions. These functions include
regular expression matching, strpbrk() function and KMP pattern searching algorithm. The strpbrk()
function is used to search a string with a specified characters. The remaining programs in the section
demonstrate the use of sort function. The programs include sorting a word in a given string, sorting
the string by ignoring white-spaces and repeating characters only once and sorting the string and
displaying the repeated characters only once.
The following section contains C programs which deals with the number of occurrences in a string.
These occurrences can be word occurrences, character occurrences or substring occurrences. It has
programs which count the number of occurrences of each character ignoring the case of alphabets
and displays them, counts the occurrences of each C keyword using array structure, program to find
the first occurrence of a character of one string in the other string, program to find the first and last
occurrence of a given character in a string and a program to count the occurrence of a substring in a
given string.
C Program to Accept 2 String & check whether all Characters in first String is Present in second String &
Print
C Program to Check whether a given Character is present in a String, Find Frequency & Position of
Occurrence
C Program to Count the Number of Occurrence of each Character Ignoring the Case of Alphabets & Display
them
C Program to Count the Occurrences of each C Keyword using Array Structure
C Program to Find the First Occurence of the any Character of String2 in String1
C Program to find First and Last Occurrence of given Character in a String
C Program to Find the Most/Least Repeated Character in the String
C Program to Count the Occurence of a Substring in String
Ordered arrangement of objects in a circular manner is called Circular permutation. The section
contains a C program to determine if one string is a circular permutation of other. The other C programs
in the section illustrate mathematical operations like calculating the binary sum of 2 binary strings
which are given as the input to the program, printing the squares of all the numbers in a string,
converting an integer to a string and vice versa and finding the sum of ASCII values of all the
characters in a given string.