C Program to Find Last Occurrence of a Character in a String

In this tutorial you will learn about the C Program to Find Last Occurrence of a Character in a String and its application with practical example.

C Program to Find Last Occurrence of a Character in a String

In this tutorial, we will learn to create a C program that will Find the Last Occurrence of a Character in a String in C programming

Table Of Contents

Prerequisites

Before starting with this tutorial we assume that you are best aware of the following C programming topics:

  • Operators in C Programming.
  • Basic Input and Output function in C Programming.
  • Basic C programming.
  • For loop in C programming.
  • Conditional Statements in C programming.

What is a string?

As we all know the String is a collection of characters. In strings, only one variable is declared which can store multiple values. The String can consist of all the typeable data it means Digits, Alphabets, Symbols, etc. In this program, we will use strings.

Algorithm:-

Find Last Occurrence of a Character in a String

In this program first, we will take input string from the user. Then we will take the character to be searched from the user. Then will Find the last occurrence of that character in that string. Printing the position of that Character.

With the help of this program, we can Find the Last Occurrence of a Character in a String.

Program:-

 

Output:-

In the above program, we have first initialized the required variable.

 

  • strg[100] = it will hold the string value.
  • ch = it will hold the character value.
  • indx = it will hold the integer value.
  • i = it will hold the integer value.

Input string from the user for the program and Take the input character from the user to search.

Searching the Character in the string.

Printing output position of the string.

In this tutorial we have learn about the C Program to Find Last Occurrence of a Character in a String and its application with practical example. I hope you will like this tutorial.