C program to compare two strings
This program will ask for two different strings from the users. We will be using the string function strcmp() here to conclude the result on the by comparing the different strings entered by the user. You need to have a priori knowledge of the following topics to understand this example in more detail.
Now see the code below.
char n1, n2;
puts("Enter first string");
puts("Enter second string");
if(i == 0)
puts("Both strings are same.");
puts("The strings are different");
Enter first string
Enter second string
The strings are different
In the above program, the values of the strings are different. As C language is the case sensitive language the strings “Program” and “program” are different. So with the function strcmp() the difference is tracked and the result is printed. strcmp() function will compare the strings character by character until there is a mismatch in the string.