Suggestions on learning C

Posted by Gadush on Thu 05 Feb 2004 09:13 PM — 3 posts, 15,768 views.

#0
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
Amended on Thu 05 Feb 2004 09:17 PM by Gadush
Canada #1
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.
Australia #2
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.)