I am trying to implement a test program to describe what this function does:
int mystery( const char *s1, const char *s2 )
{
for( ; *s1 != '\0' && *s2 != '\0'; s1++, s2++ ) {
if( *s1 != *s2 ) {
return 0;
}//end if
}//end for
return 1;
}
The program compiles and runs fine, but everytime I enter two strings, I always get a result of 0, even if they are the same length. I just can't quite figure out what I am doing wrong. Any help would be much appreciated!
#include <stdio.h>
#define SIZE 80
int mystery( const char *s1, const char *s2 ); // prototype 7
int main( void )
{
int result;
char string1[ SIZE ]; // create char array
char string2[ SIZE ]; // create char array
result = mystery(string1, string2);
puts( "Enter two strings: " );
scanf( "%79s%79s", string1, string2);
if (result == 1)
{
puts("The strings are the same length");
}
if (result == 0)
{
puts("The strings are different lengths");
}
return 0;
} // end main
int mystery( const char *s1, const char *s2 )
{
for( ; *s1 != '\0' && *s2 != '\0'; s1++, s2++ ) {
if( *s1 != *s2 ) {
return 0;
}//end if
}//end for
return 1;
}
`