Program to accept two strings and compare those two strings - 100 Most Important C# Programs

100 Most Important C# Programs

81. Program to accept two strings and compare those two strings

Code:

#include<stdio.h>

#include<conio.h>

int strcomp (char *pt1, char *pt2);

void read-string(char*pt);

main( )

{

char line [80],line2[80];

clrscr( );

printf(“enter first string;”);

read-string (line1);

printf(“enter second string”);

read-string(line2);

if(strcomp (line1,line2)>0)

printf(“second string biggest”);

else

if(strcomp (line1,line2)>0)

printf(“ first string biggest;”);

else

printf(“both the strins are equal”);

getch( );

}

void read-string(char*pt)

{

for(;(*pt=getchar( ))!=’\n’;pt++);

*pt=’\0’;

}

int strcomp (char *pt1, char *pt2)

{

for(;*pt1!=’\0’;pt1++;pt2++)

if(*pt1!=*pt2)

break;

return *pt1-*pt2;

}