
- C Programming Tutorial
- C - Home
- C - Overview
- C - Environment Setup
- C - Program Structure
- C - Basic Syntax
- C - Data Types
- C - Variables
- C - Constants
- C - Storage Classes
- C - Operators
- C - Decision Making
- C - Loops
- C - Functions
- C - Scope Rules
- C - Arrays
- C - Pointers
- C - Strings
- C - Structures
- C - Unions
- C - Bit Fields
- C - Typedef
- C - Input & Output
- C - File I/O
- C - Preprocessors
- C - Header Files
- C - Type Casting
- C - Error Handling
- C - Recursion
- C - Variable Arguments
- C - Memory Management
- C - Command Line Arguments
- C Programming useful Resources
- C - Questions & Answers
- C - Quick Guide
- C - Useful Resources
- C - Discussion
Print the string after the specified character has occurred given no. of times in C Program
Task is to print the given after the specified character occurrence for given number of times which is specified by the user
Input : string = {“I am harsh vaid “} Char =’a’ Count =2 Output : rsh vaid
It means user specified character ‘a’ and its occurrence 2 so the output string should be displayed after two occurrences of a.
Algorithm
START Step 1 -> input character in ch(e.g. ‘a’) and count(e.g. 2) as int Step 2 -> declare and initialize n with size of a string by sizeof(string)/sizeof(string[0]) Step 3 - > Loop For i to 0 and i<n and i++ IF count > 0 IF string[i]==ch Count=count-1 End IF Continue End IF Else Print string[i] End Else Step 4 -> End For STOP
Example
#include <stdio.h> int main(int argc, char const *argv[]) { char string[] = {"I am Harsh Vaid"}; char ch = 'a'; int i, count = 2; int n = sizeof(string)/sizeof(string[0]); for( i = 0; i < n; i++ ) { if(count>0) { if(string[i]==ch) { count--; } continue; } else printf("%c", string[i]); } return 0; }
Output
If we run above program then it will generate following output
rsh Vaid
- Related Articles
- How to print the maximum occurred character of a string in Java?
- C# program to get max occurred character in a String
- Program to find the kth character after decrypting a string in C++
- Check whether the specified character has a surrogate code in C#
- How to get a part of string after a specified character in JavaScript?
- Print the given 3 string after modifying and concatenating
- Function that only replaces character from string after specified appearances in JavaScript
- Convert the value of the specified string to its equivalent Unicode character in C#
- Program to balance the direction string so that each direction occurred quarter times in Python
- Splitting the string after the specified separator in Golang
- Print the longest prefix of the given string which is also the suffix of the same string in C Program.
- Program to print all substrings of a given string in C++
- C Program to print all permutations of a given string
- C++ program to concatenate a string given number of times?
- Check if max occurring character of one string appears same no. of times in other in Python

Advertisements