pages

Sunday, 18 April 2021

c-program to compare two string | c-programming

program to compare two string using strcmp function. 

In this program, we will now first take two string as input from user using gets function and store it in two character array. Now, we have to compare two strings by using strcmp function.
The strcmp() compares two strings, character by character. If the first character of both strings is equal then the next character of both strings are compared. This continues until the corresponding characters of two strings are different or a null character ‘\0’ is reached.
Do not forget to include ‘string.h’ header file.


#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
   char s1[20],s2[20];
   printf("\n enter the first string:-");
   gets(s1);
   printf("enter the second string:-");
   gets(s2);
   if(strcmp(s1,s2)==0)
         printf("\n the two string are same");
   else
         printf("the two string are not same");
   getch();
}



output:-

 


For more c-programming:-

program to count the vowel in the string

program to count the length of string by using strlen function










No comments:

Post a Comment