ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Slack 9.1 with slackware-current packages...
Posts: 164
Rep:
Text adventure command problem
Me again.
Anyway, from my last few posts in this forum, you can tell that I'm writing some kind of txt edventure (Note the e, that's the name of my 'engine' )
So, I've implemented basic commands, north, south, look, quit, etc.
But! I have not gotten 'get' down.
I have a basic object structure, shown here;
Distribution: Slack 9.1 with slackware-current packages...
Posts: 164
Original Poster
Rep:
Thanks, that fixed it.
Now I have another problem.
I have it loop through the array of items and see if they are in the room, but when I have an item named gun2, it 'get's that too.
Any ideas?
I'm not much of a C programmer (well, not much of a programmer at all) but would like to have a swing at it. Could it have something to do with the fact that strcmp() returns -1, 0 or 1? Depending on the comparison.
Distribution: Slack 9.1 with slackware-current packages...
Posts: 164
Original Poster
Rep:
That's almost what I have it do now.
No need to strcmp the location, as it is an integer, and I've removed exbuf all together.
Basically, you can type in 'get <object>' but if any other object's name starts with, for instance, 'gun', it'll pick it up too.
EDIT: Also, if strcmp returns 0, it means they match.
Distribution: Slackware 10, Fedora Core 3, Mac OS X
Posts: 617
Rep:
Hmm, thanks for teaching me a bit more about C!
Could it be something to do with the fact that strcmp() is returning -1? this would be false, so the if statement would be false ( false && true )
Just chucking that in there to see if it is the case. As far as strcmp() is concerned, gun and gun2 should return a minus one i think. It will pad the first gun to make it length 4, but the special padding at 4 will come before 2 in the alphabet causing a return of -1. I think this is how it works but then it may not and I accept I could be going down the wrong track here.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.