@database CPP_Beginners.html @remark Converted with HTML2Guide ©1997 Mark Harman @wordwrap @node MAIN "CPP_Beginners.html" @{"b"}Quick Beginners Guide to C@{"ub"} (Although I said C++, what I say applies to C also here!) This is just a simple intro for those who have never seen any C before, and never done any programming, in fact... Let's take an example program, the classic Hello World program: // Hello World! #include void main() { printf("Hello DoubleClick Readers!\n"); } And compile it. The program should output the text to the shell window. If you get an error, then look out for any mistakes. C is a case-sensitive language, to case and CASE are different! Type it exactly as you see it. Other things to watch out for are missing ; at the end of the required lines. So how does it work? Well the // is a comment, like Rem in BASIC, or ; in an AmigaDOS script. The rest of the line becomes a comment. You can also enclose comments with /* and */, eg: /* This is a Comment! */ The #include bit is required for the the printf function to work. The compiler includes the stdio.h source file (actually called a 'header file' in your program before compiling, and this is known as a preprocessor directive, but don't worry about that now. Next the void main bit. C programs are made up of lots of functions (a bit like subroutines in BASIC). Every program must have a function called main, and it is the one which initially gets executed. In fact, if you know about AmigaGuide documents, then think of the @node main, that is, every amigaguide needs a page called main, which is the first page to be displayed. Functions in C can return variables (think of Param in Amos), but void specifies that this isn't so with the main function. Likewise, you can pass parameters to a function (like with Procedures in Amos), but again, we aren't doing that with the main function, so the two brackets () are empty. Don't worry too much at the moment. The function main is defined in the curly brackets { }. Printf("..."); displays the text onto the screen. \n is a control character, and specifies that a new line be started (this isn't done by default!) Here's a list of other control characters: \n - New line \t - Tab \\ - \ (ie, two backslashes gives you one backslash) \' - ' \" - " \? - ? \0 - ASCII 0 - used to signify the end of a string Oh yes, don't forget that semi-colon. It's very easy to forget them and make all sorts of mistakes... and it won't be obvious from compiler messages what you've done wrong! ---------------------------------------- @{"b"}What Now?@{"ub"} If you want to learn C, the I would recommend getting a book of some kind - I've got 'The Beginner's Guide to C++', by Oleg Yaroshenko (Wrox). It isn't Amiga related, but keeps things very non-platform specific. C is like that, so although there are books about C on the Amiga, you don't have to worry too much (as long as it's not specifically for the PC, of course!) When it comes to the Amiga, I can recommend the Amiga C Manual, which is on disks (try PD libraries) - I don't know if it's on Aminet, or CDs. It covers the Amiga specifically, and you'll need the Amiga Includes. I find this manual and the book I have are a good complement, as the disk manual covers things like Intuition, etc, while the book just sticks with text based things, but takes the language knowledge a lot further. @{"b"}C or C++?@{"ub"} Well I'm learning C++ as I have a compiler which copes with it, so why not? Although the extra things in C++, like object orientated programming, are quite complex, it is backwardly compatible, so anything done in C will work in C++. @{"b"}So what now for my C tutorials?@{"ub"} Well in the other C++ tutorial in this issue, there's quite a jump from what I've done here. The best thing you can do is write in if you want a C tutorial, and what you want to see in it (like what level) - or even if you have something to contribute yourself! @endnode