strcmp not working at certain portions of same program (54 Views)
Reply
Occasional Contributor
tl1st3n
Posts: 4
Registered: ‎11-12-2009
Message 1 of 5 (54 Views)

strcmp not working at certain portions of same program

Hi all,

These days I come across a strange problem wherein strcmp doesn't work at certain parts of my C program. I explicitly need to compare each character of the string in the array using == with the individual alphabet. e.g. actn[0]=='R'

Has any of you come across this issue before?

string.h has been included as one of the header files.

OS: HP-UX B.11.00
CC compiler

Any input is appreciated
Honored Contributor
Steven Schweda
Posts: 9,096
Registered: ‎02-23-2005
Message 2 of 5 (54 Views)

Re: strcmp not working at certain portions of same program

> Any input is appreciated

You first. Actual code might reveal more
than a vague (and confusing) description.

> [...] e.g. actn[0]=='R'

What does that have to do with strcmp()?

> [...] strcmp doesn't work [...]

Much more likely: Your code is bad.
Acclaimed Contributor
Dennis Handly
Posts: 25,292
Registered: ‎03-06-2006
Message 3 of 5 (54 Views)

Re: strcmp not working at certain portions of same program

>OS: HP-UX B.11.00

You are out of luck, this HP-UX version isn't supported nor is the compiler. What compiler version are you using?
Honored Contributor
Laurent Menase
Posts: 1,079
Registered: ‎11-06-2003
Message 4 of 5 (54 Views)

Re: strcmp not working at certain portions of same program

I think you can consider that strcmp() is working and that the problem is elsewhere, and input strings are not the one you expect.
Maybe due to a memory corruption.
changing the code move can change the corruption footprint.
Or ending 0 is missing.
or there is a 0 at the middle of the string - which would mean it stops the comp at the first 0 encountered.




Acclaimed Contributor
Dennis Handly
Posts: 25,292
Registered: ‎03-06-2006
Message 5 of 5 (54 Views)

Re: strcmp not working at certain portions of same program

You could set a breakpoint in strcmp and then print out the arguments in gdb:
b * strcmp
x /s $r26
x /s $r25
The opinions expressed above are the personal opinions of the authors, not of HP. By using this site, you accept the Terms of Use and Rules of Participation.