I think you you use Turbo C, so
string class wont work with your compiler, because Turbo C++ is old compiler and supports AT&T C++ not ANSI C++.
And yes you should also not use gets() and puts() functions. Also clrscr() and getch() are also not standardised.
Here's the code. I have removed some unnecessary variables.
#include<string.h>
#include<conio.h>
#include<stdio.h>
int main(void)
{
clrscr();
char name1[20],name2[20];
int *ptr;
gets(name1);
gets(name2);
int s1 = strlen(name1);
int s2 = strlen(name2);
(s1<=s2)?ptr=&s1:ptr=&s2;
int x, flag=0;
for( x=0;x<*ptr;x++)
{
int ch = (int)name1[x], _ch = (int)name2[x]; // takes one character
if(ch<97) { ch+= 32; } // converts to lowercase
else if(_ch<97) { _ch+= 32; }
// if bot characters are not equal, loop is terminated.
// flag is -1 for name2 and 1 for name2 and 0 if equal
if(ch!=_ch)
{
if(ch>_ch)flag=-1; else flag=1;
break;
}
}
if(flag==1)
puts(name1);
else if(flag==-1)
puts(name2);
getch();
return 0;
}
Last edited by vishesh; Mar 12th, 2007 at 6:13 am.
Reputation Points: 85
Solved Threads: 42
Nearly a Posting Virtuoso
Offline 1,362 posts
since Oct 2006