Completely Solved C, C++ Programs Assignment.




C Program to accept two strings and compare those two strings

Filed Under:

Problem 81. C Program to accept two strings and compare those two strings.
#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=’�’;
}
int strcomp (char *pt1, char *pt2)
{
for(;*pt1!=’�’;pt1++;pt2++)
if(*pt1!=*pt2)
break;
return *pt1-*pt2;
}

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