Search

C program to compare the two strings || C Program

Code -

#include <stdio.h> 
#include<string.h> 
int main()  
{  
 char str1[20];  // declaration of char array 
 char str2[20];  // declaration of char array 
 int value; // declaration of integer variable 
   printf("Enter the first string : ");  
   scanf("%s",str1);  
   printf("Enter the second string : ");  
   scanf("%s",str2);  
 // comparing both the strings using strcmp() function 
   value=strcmp(str1,str2);  
 if(value==0)  
   printf("strings are same");  
 else 
   printf("strings are not same");  
 return 0;  
}  

Output -

Enter the first string sam
Enter the second string sam
strings are same

3 views0 comments

Related Posts

See All

Program of Random Number in C || C Programs

Code - #include <stdio.h> #include <conio.h> #include <stdlib.h> void main() { // use rand() function to generate the number printf (" The random number is: %d", rand()); pri

Getchar() function in C || C Programs

Code - #include <stdio.h> #include <conio.h> void main() { char c; printf ("\n Enter a character \n"); c = getchar(); // get a single character printf(" You have passed ")

  • 1024px-Telegram_logo.svg
  • download
  • YouTube