String Programs in C

C Programming Examples - Strings

In C programming, a string is a one-dimensional array of characters that ends with the special character ‘\0’. Character arrays or strings are used to manipulate text, such as words or sentences. In strings, the termination character (‘\0’) is very important because it is the only way to detect where the string ends. Strings can be written as character arrays or string literals in the C language. The most commonly used string functions are strlen(), strcmp(), strcpy(), strchr(), and strcat().

The following section contains various C programs related to strings, string operations, string functions, palindrome programs, string programs using recursion, frequency, and occurrence of characters in a string. C programs on string matching, approximate string matching, and encryption algorithms are also covered with examples. Each sample program on the linked list includes a program description, C code, and program output. All examples have been compiled and tested on Windows and Linux systems.

Here is the listing of C programming examples on Strings:

  1. C Programs on Palindome
  2. C Programs on String Operations
  3. C Programs on String Functions
  4. C Programs on Strings
  5. C Programs on Frequency of Characters in a String
  6. C Programs on Count Occurrences of a Character in a String
  7. C Programs on String using Recursion
  8. C Programs on String Matching
  9. C Programs on Cryptography
  10. C Programs on Longest Common SubString/SubSequence

1. C Programs on Palindome

Program Description
String Palindrome Program in C C Program to Check if a Given String is Palindrome
Palindrome String using Recursion in C C Program to Check whether a String is Palindrome or not using Recursion
Palindrome String without Built-in Function in C C Program to Check if a String is a Palindrome without using Built-in Function
Smallest and Largest Palindrome in C C Program to Find Smallest and Biggest Possible Word which is Palindrome in a String

advertisement
advertisement

2. C Programs on String Operations

Program Description
String Concatenation in C C Program to Concatenate Two Strings
Concatenate Two Strings Lexically in C C Program to Concatenate Two Strings Lexically
Compare Two Strings in C C program to Compare Two Strings
Find Substring in a String in C C Program to Check if the Substring is Present in the Given String
Length of a String without Built-in Function in C C Program to Find the Length of a String Without using Built-in Function
Insert Character in String in C C Program to Insert Character/Word in Any Desired Location in a String
Remove Duplicate Words from String in C C Program to Delete All Repeated Words in String

3. C Programs on String Functions

Program Description
Remove Word from String in C C Program to Remove Given Word from a String
Remove Characters in Second String which are present in First String in C C Program to Remove Characters in Second String which are present in First String
Replace all Characters by Lowercase in C C Program to Replace All Characters by Lowercase
Capitalize First Letter of Each Word in a String in C C Program to Capitalize First Letter of Each Word in String
Reverse Each Word in a String in C C Program to Reverse Each Word in a String
Regular Expression Matching in C C Program to Implement Regular Expression Matching
strpbrk() Function in C C Program to Implement strpbrk() Function

4. C Programs on Strings

Program Description
Sum of Numbers in String in C C Program to Read a String and Find the Sum of all Digits in the String
Largest and Smallest Word in a String in C Program to Find the Largest and Smallest Word in a String
Maximum Occurring Character in a String in C C Program to Find the Most and Least Repeated Character in the String
Words Ending with Letter S in C C Program to Print the Words Ending with Letter S
Permutation of a String in C C Program to Print All Permutations of a Given String
List All Lines Containing a given String in C C Program to List All Lines Containing a Given String
Check if Two Strings are Permutation of Each Other in C C Program to Check if Two Strings are Permutation of Each Other
Anagram Program in C C Program to Check whether Two Strings are Anagrams
Find Position of 1-bits in C C Program to Find the Position of 1-bits
ASCII Value of a String in C C Program to Print Ascii Value of All Characters in the String
Sum of ASCII Value of a String in C C Program to Find the Sum of ASCII Value of All Characters in the String
Prime String Program in C C Program to Display All Characters Present in the Prime Position of a String
C Program to Display All Combinations of Two Words from String without Repeated Combinations C Program to Print All Possible Combination of Two Words from the String without any Repetition
Print Common Characters of Two Strings in C C Program to Check Whether All Characters in First String is Present in Second String
Square String in C C Program to Print the Square of all the Numbers in a String
Binary Addition of Strings in C C Program to Add Two Binary Strings
Add Two Binary Strings in C C Program to Input 2 Binary Strings and Print their Binary Sum
Convert Integer to String and Vice-versa in C C Program to Convert Integer to String and Vice-versa
Grep, Egrep and Fgrep in C C Program to Implement Grep, Egrep and Fgrep Commands

5. C Programs on Frequency of Characters in a String

Program Description
Highest Frequency Character in a String in C C Program to Find Highest Frequency Character in a String
Frequency of Each Word in a String in C C Program to Find the Frequency of Each Word in a String
Frequency of “the” Word in a String in C C Program to Find the Frequency of “the” Word in a String
Frequency of a Substring in a String in C C Program to Find the Frequency of a Substring in a String
Find Frequency of Characters in a String in C C Program to Find Frequency and Position of Characters in a String
Count Repeated Words from a String in C C Program to Count Repeated Words from a String
Find all Subsets of a String in C C Program to Find All Possible Subsets of a String
Find all Subsets of given Length in String in C C Program to Find All Possible Subsets of Given Length in String

6. C Programs on Count Occurrences of a Character in a String

Program Description
First and Last Occurrence of Character in a String in C C Program to Find First and Last Occurrence of Character in a String
Find Consecutive Occurrence of Vowel in a String in C C Program to Find Consecutive Occurrence of Vowel in a String
Find all Occurrences of a Substring in String in C C Program to Count the Occurrence of a Substring in String
Count Particular Repeated Word in String in C C Program to Count Particular Repeated Word in a String
Count Occurrence of Each Character in String in C C Program to Count the Occurrence of Each Character in String
Count Number of Words from a String in C C Program to Count Number of Words in a String
Count Unique Words from a String in C C Program to Count Number of Unique Words in a String

7. C Programs on String using Recursion

Program Description
First Uppercase Letter in a String using Recursion in C C Program to Find the First Capital Letter in a String using Recursion
First Uppercase Letter in a String without Recursion in C C Program to Find the First Capital Letter in a String without Recursion
String Length using Recursion in C C Program to Find the Length of the String
String Copy using Recursion in C C Program to Copy One String to Another using Recursion
Reverse a String using Recursion in C C Program to Reverse a String using Recursion
Reverse a String using Recursion and Iteration in C C Program to Reverse a String using Recursion and Iteration

advertisement

8. C Programs on String Matching

Program Description
Naive String Matching in C C Program to Perform Naive String Matching
Knuth Morris Pratt Algorithm in C for Pattern Searching C Program to Implement Knuth-Morris-Pratt Algorithm for Pattern Searching
Knuth Morris Pratt Algorithm in C C Program to Implement KMP Pattern Searching Algorithm
Boyer Moore Algorithm in C C Program to Implement Boyer-Moore Algorithm for Pattern Searching
Rabin Karp String Matching Algorithm in C C Program to Implement Rabin-Karp Method for Pattern Searching
Online String Matching using Wagner and Fisher in C C Program to Implement Wagner and Fischer Algorithm for Online String Matching
Levenshtein Distance Computing Algorithm in C C Program to Implement Levenshtein Distance Computing Algorithm
String Matching Using Library in C C Program to Perform String Matching Using String Library
String Search Algorithm in C C Program to Implement String Search Algorithm for Short Text Sizes
Repeated Search Pattern in C C Program to Repeatedly Search the Same Text

9. C Programs on Cryptography

Program Description
Monoalphabetic Cipher in C C Program to Implement the Monoalphabetic Cipher
Caesar Cipher in C C Program to Implement Caesar Cipher
Vigenere Cipher in C C Program to Implement the Vigenere Cipher
Hill Cipher in C C Program to Implement the Hill Cipher
Affine Cipher in C C Program to Implement Affine Cipher
Playfair Cipher Encryption Program in C C Program to Encrypt Message using Playfair Cipher
RSA Algorithm in C C Program to Implement the RSA Algorithm
Transposition Technique Program in C C Program to Perform Cryptography using Transposition Technique
Checksum Program in C C Program to Implement the Checksum Method for Small String Messages

10. C Programs on Longest Common SubString/SubSequence

Program Description
Longest Repeating Subsequence in C C Program to Find Longer Repeating Sequence
Length of Longest Repeating Subsequence in C C Program to Find the Length of Longest Repeating Subsequence
Longest Increasing Subsequence in C C Program to Find the Longest Increasing Subsequence

advertisement
advertisement
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.