C Program to Compare two Strings

In this tutorial you will learn about the C Program to Compare two Strings and its application with practical example.

C Program to Compare Two Strings

In this tutorial, we will learn to create a C program that will Compare Two Strings 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 of C programming.
  • For loop and its concepts in C Programming.
  • Conditional Statements in C Programming.

Algorithm:-

What is a string?

As we all know, the string is a collection of characters, symbols, digits, and blank spaces. In strings, only one variable is declared which can store multiple values.

Compare Two Strings 

First will take the elements of string 1 from the user. Then will take the elements of string 2 from the user. Then will compare the two taken strings without using the predefined functions. i.e. compare them without using the strcmp function.

With the help of this program, we can Compare Two Strings.

Program code:-

Output:-

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

  • string1[100] = it will hold the string value.
  • string2[100] = it will hold the string value.
  • i = it will hod the integer value that will control the for loop

Taking Input string 1 from the user.

Taking Input string 2 from the user.

Printing Output compared string.

In this tutorial we have learn about the C Program to Compare two Strings and its application with practical example. I hope you will like this tutorial.