Você está na página 1de 5

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.

C Program to Check if a given String is Palindrome


C Program to Check if a String is a Palindrome without using the Built-in Function
C Program to Check whether a given String is Palindrome or not using Recursion
C Program To Print Smallest and Biggest possible Word which is Palindrome in a given String
C Program to Find the Largest & Smallest Word in a String

2. C Examples on String Operations

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.

C Program to read two Strings & Concatenate the Strings


C Program to Concatenate two Strings Lexically
C Program to Check if the Substring is present in the given String
C Program to Accepts two Strings & Compare them
C Program to Find the Length of a String without using the Built-in Function

3. C Examples on Replace, Remove and Reverse Functions


The following section deals with three more operations that can be performed on a given string. They
are Replace, Remove and Reverse. Replace function replaces the occurrences in a given string.
Remove deletes the characters from the specified positions and Reverse function reverses the
characters of a string. The C programs in this section uses the replace function to replace lowercase
characters by uppercase and vice-versa, to replace all string characters by lowercase. It removes a
given word from the string, removes all the repeated words in a string, removes all the characters in
the second string which are present in the first string.The C programs also use the reverse function to
reverse the string using recursion and iteration both and to reverse every word of the given string. The
remaining C programs demonstrate the count operation. They count the number of vowels and
consonants in a section and counts the total number of words in a sentence using command line
argument.

C Program to Replace Lowercase Characters by Uppercase & Vice-Versa


C Program to Remove given Word from a String
C Program to Remove all Characters in Second String which are present in First String
C Program to Replace all the Characters by Lowercase
C Program to Reverse the String using Recursion
C Program to Reverse every Word of given String
C Program to Count the Number of Vowels & Consonants in a Sentence
C Program to Delete All Repeated Words in String
C Program to Reverse the String using Both Recursion and Iteration
C Program to Count the Total Number of Words in the Sentence using Command Line Argument

4. C Examples on finding the Frequency of Occurrences of Characters in a String

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.

C Program to Find the Frequency of the Word the in a given Sentence


C Program to Read a String and find the Sum of all Digits in the String
C Program to Copy One String to Another using Recursion
C Program to find the First Capital Letter in a String using Recursion
C Program to find the First Capital Letter in a String without using Recursion
C Program to find the Length of the String using Recursion
C Program to find Longer Repeating Sequence
C Program to Find the Frequency of Substring in the given String
C Program to Find the Frequency of Every Word in a given String
C Program to Find Highest Frequency Character in a String
C Program to Find the Length of the Longest Repeating Sequence in a String
C Program to find the possible subsets of the String

5. C Examples on Displaying, Inserting and Printing the characters in 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.

C Program to Check whether two Strings are Anagrams


C Program to Display every possible Combination of two Words or Strings from the input Strings without
Repeated Combinations
C Program to List All Lines containing a given String
C Program to Print the Words Ending with Letter S
C Program to Insert Character/Word in any Desired Location in a String

6. C Examples on implementation of Functions and Algorithms

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.

C Program to Implement Regular Expression Matching


C Program to Implement strpbrk() Function
C Program to Implement the KMP Pattern Searching Algorithm
C Program to Sort Word in String
C Program to Sort String Ignoring Whitespaces and Repeating Characters Only Once
C Program to Sort the String and Repeated Characters should be present only Once

7. C Examples on the usage of Count Function and Search Method


The programs in this section illustrates the use of count function and search method. The count
function is used to count the number of occurrences of the given word in a string and the search
method searches for the specified word in the string. The programs in this section counts the number
of unique words, counts the number of words in a given text or sentence and searches for a word in
the given string and replaces it with a given specified word. It also has programs to display the
characters at a specified position in the given string and display the combination of two words of two
given strings without any repetition.

C Program to Count the Number of Unique Words


C Program to Search a Word & Replace it with the Specified Word
C Program to Display the Characters in Prime Position a given String
C Program to Count Number of Words in a given Text Or Sentence
C Program to Print Combination of two Words of two given Strings without any Repetition
C Program to Display Every Possible Combination of Two Words from the given 2 String without
Displaying Repeated Combinations

8. C Examples demonstrating the Occurrences in a given String

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

9. C Examples demonstrating Simple Mathematical Operations on Strings

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.

C Program to Determine if One String is a Circular Permutation of Another String


C Program to Find the Consecutive Occurrence of any Vowel in a String
C Program to Input 2 Binary Strings and Print their Binary Sum
C Program to Input a String with at least one Number, Print the Square of all the Numbers in a String
C Program which Converts an Integer to String & vice-versa
C program that takes input as 2323 and gives output as 2332. ie. the new number should be greater than the
previous number but should have the same digits
C Program to Find the Sum of ASCII values of All Characters in a given String

Você também pode gostar