I'm using turbo C++ to compile the program. The program is
main()
{
char inp1[21],inp2[21];
int nsame=0,i=0,l1,l2;
clrscr();
gets(inp1);
gets(inp2);
l1=strlen(inp1);
l2=strlen(inp2);
if(l1==l2)
{
for(;inp1[i]!='\0',inp2[i]!='\0',inp1[i]==inp2[i];i++)
{
nsame++;
}
}
if(nsame==l1)
{
puts("Same");
}
else
{
puts("Not the same");
}
getch();
}
The for loop above runs an extra time so the nsame is greater than the correct value by 1. So the program's output is correct if an extra nsame--; is added.