Platform : WindowsXP
Compiler : VC++ 6
Question 1 :
Here's a program using strcmp() :
Code:
#include <stdio.h>
#include <string.h>
int main(void)
{
char s1[50], s2[50];
printf("s1 : ");
fgets(s1, sizeof(s1), stdin);
printf("s2 : ");
fgets(s2, sizeof(s2), stdin);
if(strcmp(s1, s2) == 0)
printf("s1 == s2\n");
else if(strcmp(s1, s2) < 0)
printf("s1 is less than s2\n");
else if(strcmp(s1, s2) > 0)
printf("s1 is greater than s2\n");
return 0;
}
I already know what strcmp() does , but my question is how does it actually compare the two strings? if you enter "aa" as s1 and "AAAAAAAAA" as s2 (for example) ; strcmp() would return '+1' wich means s1 is greater than s2
Question 2 :
I never had to flush the output buffer in my programs before, because they seemed to run well and updating ouput as they should. But some programmers told me that some systems won't update the output untill it recieves a new line (\n) or when the output is manually flushed with fflush(stdout), Is this true? and if so , is this the only reason that programmers need to flush output?
Thanks in advance