[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  SMAUG
. -> [Folder]  SMAUG coding
. . -> [Subject]  Suggestions on learning C

Suggestions on learning C

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Gadush   (92 posts)  [Biography] bio
Date Thu 05 Feb 2004 09:13 PM (UTC)

Amended on Thu 05 Feb 2004 09:17 PM (UTC) by Gadush

Message
I am trying to learn C, but I am finding it difficult. C books are not so easy to find. I have a book Weekend Crash Course in C++, but I have found that C++, while helping me learn basic programming and a lot like C, is not C.
I have many ideas I want to make work with the Smaug code, but I lack the necessary skills to see most of them to completion. Additionally, there seem to be many unique methods in Smaug that the various online tutorials of C I have gone through never mention.
Greven gave me some advice on setting variables, but I am afraid I can't understand it well enough.
For instance, what does atoi mean? None of the C tutorials mention it. Also, everywhere in the code I see things like
room->x = atoi(xcoord);
What is the -> ? It seems like it is saying if the first is in the second.
Does anyone know of a good MUD code tutorial, that not only helps with basic C, but offers some insight into the actual Smaug code itself?
Thanks for any advice.
Gadush
[Go to top] top

Posted by Greven   Canada  (835 posts)  [Biography] bio
Date Reply #1 on Thu 05 Feb 2004 09:47 PM (UTC)
Message
Well, in regards to those specific questions, I'll see if I can help.

Atoi is a standard function that will take a string pointer( something that is declared as "char *string"). This then returns an interger. The reason for this is that while you may enter 12345 into the command, it is interpreted as a string of characters, not a number. So, atoi will make it a number, since you cannot directly cast a character string as a number(dunno if you've learned about casting).

The room->xcoord part is different. The "room" section of it is of type ROOM_INDEX_DATA. This is similiar to types int, char, float, etc, except that it was created by the coders. Picture it like a tree. The trees name is "room". Now, each branch in the structure has different types. It can have another ROOM_INDEX_DATA, pointing to a different tree, or it can have xcoord, an int, or it can have a character string, like name. To specify which part you want to read/change/access, you use "room->xcoord". This means "access the variable called xcoord in this room tree." Technically, I think room->xcoord is the same as (*room).xcoord, if you've read up on structures.

As for mud coding guides, I haven't found a good one. There are several different c archives that can explain things( one of the ones I use is http://www.unix.geek.org.uk/~arny/info/library_toc.html ). These can help, but I've found looking through the code for a specific function, knowing what the outcome is, and then looking at the code to see how it was done is the best way to learn. These forums are also a great way to learn.

If I've messed something up, someone please correct me.

Oh, another way to figure out what what a specific function can do, at your shell, type "man atoi". This will give you a description of what it does, whats required, and mor than you'll ever need to know on it. Please note though, that this will only work for system commands, not one written by the smaug coders.

Hope this helps.

Nobody ever expects the spanish inquisition!

darkwarriors.net:4848
http://darkwarriors.net
[Go to top] top

Posted by Mademoiselle   Australia  (35 posts)  [Biography] bio
Date Reply #2 on Thu 05 Feb 2004 10:26 PM (UTC)
Message
I would suggest, if you have a *nix box lying around somewhere, you learn C on that, rather than on Windows. Why? Because on a *nix box you normally have a nice man page for every C function available (most of which are also available under Windows). Not sure what "atoi" does? Just 'man atoi' in a terminal, and you're away.

C had me completely stumped for the longest time, too; since switching from windows to FreeBSD at home (about a year ago), however, I've improved out of sight. Now I'm looking into Windows programming again and I'm pretty confident I'll pick it up in a snap, as soon as I hunt down a decent book... (Got my eye on one, now I just need money.)
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


11,140 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]