-
String question
I've gotten everything all sorted out for my little program. I followed the link to Dsock found here aswell to get Dsock.h for handling my sockets. Now I just need to figure out how to search this string.
Strength: 15 Intelligence: 12 Wisdom: 16 Dexterity: 16 Constitution: 15
To cross reference the stats defined by the user, versus the stats given from the socket. Then act upon it. This is what I have. However it doesn't work.
Code:
from = ReadCommand(s, buf);
if (from[0] != 'S')
return;
// str
stat = (from[10]-48) * 10 + from[11]-48;
if (stat < str){
write_to_socket("no\n");
return;
}
// int
stat = (from[27]-48) * 10 + from[28]-48;
if (stat < in){
write_to_socket("no\n");
return;
}
// wis
stat = (from[38]-48) * 10 + from[39]-48;
if (stat < wis){
write_to_socket("no\n");
return;
}
// dex
stat = (from[52]-48) * 10 + from[53]-48;
if (stat < dex){
write_to_socket("no\n");
return;
}
// con
stat = (from[69]-48) * 10 + from[70]-48;
if (stat < con){
write_to_socket("no\n");
return;
}
write_to_socket("yes\n");
I got the code from a guy who built this feature into his MUD client. I assumed it would work outside of its environment. I assumed wrong. ;)
-
Maybe i'm just dense, but I don't quite follow. I thought there was a thing in strings to count over a certain number. Since the chars over to the stat isn't going to change. That would be the easiest.
-
My apologies. I was just giving an example of what I had to give you an idea of what I was trying to do.
I want to take this.
Strength: 15 Intelligence: 12 Wisdom: 16 Dexterity: 16 Constitution: 15
and search the string, and cross reference each number against a number thats defined by the user.
So I want to take strength as 15, and check it against strength entered by the user to see if its equal or less than.
I'm just not certain how to get it over to the tenth character, then over to the 27th and so on.