Completely Solved C, C++ Programs Assignment.




C Program to accept two string and compare the strings are equal or not

Filed Under:

Problem 47. C Program to accept two string and compare the strings are equal or not
#include<stdio.h>
#include<conio.h>
int getline (char line[ ], int lim );
int strc(char str1[ ], char str2[] );
main( )
{
char str1[80],str2[80];
int comp;
clrscr( );
printf(“enter first string:”);
getline(str1,80);
printf(“enter second string:”);
getline(str2,80);
comp=strc(str1,str2);
if(comp>0)
printf(“first string is bigger”);
else
if(comp==0)
printf(“both the strings are equal”);
getch( );
}
int getline(char str[], int lin)
{
int i;
for(i=0;i<lin&&((str[i]=getchar())!=’n’);i++);
if(str[i]=’�’)
return i;
}
int strc(char str1[],char str2[])
{
int i;
for(i=0;str1[i];i++)
if(str1[i]!=str2[i])
return str1[i]-str2[i];
return str1[i]-str2[i];
}

C compiler: gcc 4.1.2

 Back to main directory: Sample C Program | Software Practical | Solved C Assignment


Get Free Programming Tutorials and Solved assignments