Thread: String question

  1. #1
    Registered User Twiggy's Avatar
    Join Date
    Oct 2001
    Posts
    43

    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.
    To error is human, to really foul things up requires a computer

  2. #2
    Registered User Twiggy's Avatar
    Join Date
    Oct 2001
    Posts
    43
    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.
    To error is human, to really foul things up requires a computer

  3. #3
    Registered User Twiggy's Avatar
    Join Date
    Oct 2001
    Posts
    43
    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.
    To error is human, to really foul things up requires a computer

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Reusing a string pointer question
    By chiefmonkey in forum C++ Programming
    Replies: 3
    Last Post: 05-06-2009, 04:53 PM
  3. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM
  4. String array question
    By gogo in forum C++ Programming
    Replies: 6
    Last Post: 12-08-2001, 06:44 PM