I have two concerns in the below code.
(1) If I replace gets (str1) with scanf (%d, str1) it doesn't work.
(2) I entered first string as "tina" and second string as "leena is god" so the first string length was "4", the second one was "12". So it should be "str1 is less than str2" but output was "str1 is greater than str2".
I wonder why it shows it is greater when in fact it is lesser than str2 .
Code:
int main(void)
{
int str1, str2, i;
clrscr ();
printf ("Please enter the string1\n");
gets (str1);
printf ("Your string1 length is %d\n", strlen(str1));
printf ("Please enter the string2\n");
gets (str2);
printf ("Your string2 length is %d\n", strlen(str2));
i = strcmp(str1, str2);
if (i = 0)
printf ("str1 is equal to str2");
if (i < 0)
printf ("str1 is less than str2");
if (i > 0)
printf ("str1 is greater than str2");
getch ();
return 0;
}