Avatar

ɤ6od53nt

Casts Magic Missile

Games | Blogs | Screenshots | Pictures | Fan Art

yup, this is an ad!
Blog

something like peasantquest!


Blog Code
  • Mood: it's Friday, schools almost over. I'm happy!
  • Playing: Napalmriot
  • Watching: reflection on compy screen (or news to be technical)
  • Listening: KUTLESS!
  • Reading: scarlet letter doesn't count
  • Drinking: gatorade
  • Eating: cereal

Hey! It's been a while since I updated the community on my C progress. I thought I'd jump in here and say a bit. I was toying around with strings and decided to test equivalences between a set string and an inputted string. something like this (assume variables are previously assigned):

strgcpy(strg1,"yes");
scanf("%s",&strg2);
if (strg1 == strg2)
{
printf("success");
getchar();
}
else
{
printf("failure");
getchar();
}

my guess is that it won't work because I'm not accounting for the null character that is automatically used to end a set string. I dunno, it could be something else. If you know off the top of your head, feel free to tell me. btw, since I'm still new to C and C++ I use the getchar() function to temporarily pause the program. I don't know any other way to do it. Nor have I figured out exactly what the getchar() function is for besides a literal keyboard/mouse scanf(). I'm assuming it's like getkey on the calculator, but I haven't gotten far enough for it to matter.

another thing, what this has to do with peasantquest. As some or all of you may know, peasantquest is based on text input directions. to pick something up, you literally type "take stick" or "take baby". ;) I wanted to see if I could develop a minor search engine of sorts. Something that will discern between what matches the inputted text and what doesn't. That was the first step, and i got shut down... XD

Comments

    • Avatar
      Rank
      Staff Sergeant
      Creed
      Action
      Joined
      12.18.07

    ʊIrishancest

    Legally Certified Warthog Operator

    One problem is that the real way you are supposed to compare strings is to use the srtcmp() function, with the two inputs being the two strings. I believe it returns 1 if true and something else if false. I'm not sure if it's case sensitive, but I believe it is. Also, if when you say you want to pause the program to mean you want it to wait for user input such as enter, there is a real way to do it but I can't remember off the top of my head. Anyways, I hope that was a bit of help.
    ---
    Beware. The Internewt is real!
    I'll have a loil, on the rocks.
    Come Riot over in Napalm Chat: http://www.napalmriot.com/chat/
    05.30.08 10:22 pm
      • Avatar
        Rank
        Private
        Creed
        Role-Playing
        Joined
        12.27.07

      ɤ6od53nt

      Casts Magic Missile

      (as a note, there is no strgcpy() to my knowledge. it's properly spelled strcpy(). That's a fail on my part)

      It was a great help. for one thing, I'm being too slow today to remember strcmp(). I looked it up and made myself feel pretty much dumber than I already had been feeling today. Another thing, yes, it returns 1 if true, and pretty much any number BUT 1 if false. I have yet to figure out any pattern to what none "1" number the program picks.
      ---
      "For the Glory of my LORD God!" --outcome of my first program
      05.30.08 10:31 pm
    • Avatar
      Rank
      Staff Sergeant
      Creed
      Action
      Joined
      12.18.07

    ʊIrishancest

    Legally Certified Warthog Operator

    The pattern is that it converts the letters to their ascii values and then returns the difference of 2 minus 1 i think. So the longer the second word the larger the number, or vice versa if it's 1 - 2. There is also a strncmp() which does the same thing as strcmp() except you have the option to only compare a certain number of chars. I also wrote my own strcmp for school that isn't case sensitive, but I'd have to dig that up. Glad I could help though.
    ---
    Beware. The Internewt is real!
    I'll have a loil, on the rocks.
    Come Riot over in Napalm Chat: http://www.napalmriot.com/chat/
    05.30.08 10:45 pm
      • Avatar
        Rank
        Private
        Creed
        Role-Playing
        Joined
        12.27.07

      ɤ6od53nt

      Casts Magic Missile

      well hey, if you happen upon that file, send a sample my way. I can't even fathom how to make something not case sensitive in C yet!

      6od53nt == noob!! ;)
      ---
      "For the Glory of my LORD God!" --outcome of my first program
      05.30.08 11:12 pm
        • Avatar
          Rank
          Staff Sergeant
          Creed
          Action
          Joined
          12.18.07

        ʊIrishancest

        Legally Certified Warthog Operator

        So you know that all letters have an equivalent ascii numerical equivalent. So basically you check if it is within the capital or lowercase range, and then set it specifically to one or the other. You do this to every character in both strings, and then compare. At that point they should all be either uppercase or lowercase, depending on what you chose. That is the basics of it at least. If I find the code, I'll definitely show it to you. And if you need more of an explanation, i can give it to you.
        ---
        Beware. The Internewt is real!
        I'll have a loil, on the rocks.
        Come Riot over in Napalm Chat: http://www.napalmriot.com/chat/
        05.30.08 11:20 pm