Hi,
In the following code, as far as I can tell, I get identical strings, but strcmp does not return 0.
{
int controlLoop = 0, charLoop = 0, index = -1;
char stateSelect[STATESIZE] = { '\0' };
for ( controlLoop = 0; controlLoop < STATES; controlLoop++ )
{
if ( controlLoop % 3 == 0 )
printf( "\n" );
printf( "%-25s", array[controlLoop].stateName );
}
printf(" \n\n\n" );
printf( "Select State for Display or (E)xit:\n\n" );
scanf( "%s", &stateSelect );
stateSelect[0] = toupper( stateSelect[0] );
for ( charLoop = 1; charLoop < STATESIZE; charLoop++ )
{
if ( isalpha(stateSelect[charLoop] == 0 ))
stateSelect[charLoop] = '\0';
else
stateSelect[charLoop] = tolower( stateSelect[charLoop] );
}
printf("%s*", stateSelect);
printf("\n%s*\n", array[1].stateName);
for ( controlLoop = 0; controlLoop < STATES; controlLoop++ )
{
if ( strcmp( stateSelect, array[charLoop].stateName ) == 0 )
index = controlLoop;
}
return index;
}
I added the printf statements witht the "*" for debugging. They print out identically with the "*" immediately following the last letter in both cases.
Any help would be appreciated.
David
In the following code, as far as I can tell, I get identical strings, but strcmp does not return 0.
{
int controlLoop = 0, charLoop = 0, index = -1;
char stateSelect[STATESIZE] = { '\0' };
for ( controlLoop = 0; controlLoop < STATES; controlLoop++ )
{
if ( controlLoop % 3 == 0 )
printf( "\n" );
printf( "%-25s", array[controlLoop].stateName );
}
printf(" \n\n\n" );
printf( "Select State for Display or (E)xit:\n\n" );
scanf( "%s", &stateSelect );
stateSelect[0] = toupper( stateSelect[0] );
for ( charLoop = 1; charLoop < STATESIZE; charLoop++ )
{
if ( isalpha(stateSelect[charLoop] == 0 ))
stateSelect[charLoop] = '\0';
else
stateSelect[charLoop] = tolower( stateSelect[charLoop] );
}
printf("%s*", stateSelect);
printf("\n%s*\n", array[1].stateName);
for ( controlLoop = 0; controlLoop < STATES; controlLoop++ )
{
if ( strcmp( stateSelect, array[charLoop].stateName ) == 0 )
index = controlLoop;
}
return index;
}
I added the printf statements witht the "*" for debugging. They print out identically with the "*" immediately following the last letter in both cases.
Any help would be appreciated.
David