Program to accept two string and compare the strings are equal or not - 100 Most Important C# Programs

100 Most Important C# Programs

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

Code:

# 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]=’\0’)

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];

}