Link to home
Start Free TrialLog in
Avatar of icysmarty
icysmarty

asked on

strncmp

HI

I am experiencing problem with following statement
int comp = strncmp((array+middle),target,strlen(target));

I am trying to compare the target (player name) with the player name at array+middle position
However, by using strncmp, I do not get expected result because of 'strlen(target)'

For instance,

array+middle  --> super_player
target --> su

this two are not same but in fact the statement return 0 since I am only comparing su with super_player

I am wondering how can I compare su with the entire "super_player" instead of su

This statement is for comparison in my  binary search statement.
Avatar of peterchen092700
peterchen092700

you don't need strncmp for that.


array+middle is a perfectly valid string (e.g. if array == "the super_player", array+4=="super_player")
so in fact you can use

strcmp(array+middle, target)
Avatar of icysmarty

ASKER

strcmp does not work for my case cause the array has fixed-length record of playername

like
array ={superman--ultraman--hero------andsoon---}
- stands for space
ASKER CERTIFIED SOLUTION
Avatar of peterchen092700
peterchen092700

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Yeah, you are right.
I should do that.