icysmarty
asked on
strncmp
HI
I am experiencing problem with following statement
int comp = strncmp((array+middle),tar get,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.
I am experiencing problem with following statement
int comp = strncmp((array+middle),tar
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.
ASKER
strcmp does not work for my case cause the array has fixed-length record of playername
like
array ={superman--ultraman--hero ------ands oon---}
- stands for space
like
array ={superman--ultraman--hero
- stands for space
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Yeah, you are right.
I should do that.
I should do 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)