Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with strcmp

Status
Not open for further replies.

PowerNuke

Programmer
Oct 7, 2001
10
0
0
US
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( &quot;\n&quot; );
printf( &quot;%-25s&quot;, array[controlLoop].stateName );
}

printf(&quot; \n\n\n&quot; );
printf( &quot;Select State for Display or (E)xit:\n\n&quot; );
scanf( &quot;%s&quot;, &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(&quot;%s*&quot;, stateSelect);
printf(&quot;\n%s*\n&quot;, 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 &quot;*&quot; for debugging. They print out identically with the &quot;*&quot; immediately following the last letter in both cases.

Any help would be appreciated.

David
 
Never Mind folks! My stupid error. If you'll notice, I reference the wrong loop control variable in the last loop. :/

Oh well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top