Learning C: lesson I Hello, this is Alexander. I am writing this for those people who want to learn how to program in C, but are scared of it. It is scary, but it is not hard, well, it is hard, but it is a great feeling making a game, or a program of no value, but knowing that YOU made it. This is for the same reason that I code my own HTML, even with so many different ways to use a editor. I like to know that I made it, that I didn't just say what I wanted. If you want this sense of accomplishment, then read on. C is a programming language, of course. It is a programming language of many different dialects, just like each language that is spoken has many dialects. In C though, they are not because the 'speakers' live in the North, South, or grew up in some other place, it is because there are so many compilers. There are about four major ones: Borland C++, Microsoft Visual C++, Watcom C/386, and DJGPP. You can download DJGPP from one of the pages connected to my site and go to the programming part, or you may have another compiler. I also hope to upload the shareware version of Turbo C++, which is very similar to Borland C++. Each of these compilers is a little different. The library functions of one will have all of ANSI C, the standard, but will have many other functions, or to continue my analogy, 'words'. What I am getting at is that some of the stuff I use in this may have to be changed. If I say #include "malloc.h", you have need to say #include "alloc.h". It is because there are so many different ways of 'saying' something that sometimes it is hard to communicate, take a Southerner, and a Northerner. There are often words that get confused. So, anyway, if you don't have a compiler, I strongly suggest you get one, a simple one is good enough for my lessons, if they are worthy of that title ;), but get one. C is a different breed of programming. It has only 33 keywords for DOS, and it has no keywords to use for output. This means that almost everything is stored in a -header file-(note: all terms of interest will be set off, but I can't bold). This gives the use of many functions. But lets see a real program... #include void main() { cout<<"HEY, you, I'm alive!"; } So, that sure looks easy doesn't it. Some of the stuff is weird. Okay, lets break it down. The -#include- is a preprocessor directive, one that tells the compiler to put all the stuff in the header file -iostream.h- into our program! This allows me to use some functions later on. Also, for most header files you can also use " " to surround the name instead of <>. The next thing is -void main()- what this is saying is that I am going to have a function called -main-, and that it returns no value, hence -void-. Then those little -{- braces are used. They are like the BEGIN and END commands of pascal. basically they are used to define aresa of some function, or other things we will learn of later. The next thing is strange. If you have programmed in other languages you might think that print would be used to display text. It can be, but only if you use a function called -printf("text goes here");- the cout command can be used to display text but it needs those strange << things known as insertion operators, basically use it to put text on the screen. The quotes tell it to put the string as-is on the screen. After that, the little -;- is used to tell it that that is the end of that function. After, the braces close off the function. Pretty simple, eh? You can try out this program if you want, just cut and paste it. You should also know comments. To comment you can either use // which goes to the end of the line, or you can sue the /* and then */ to make a comment. This is useful. Make sure that you know how to use it, or you might accidentally comment out a huge chunk of code! You may be thinking by now that that is fine and good, but what If I want INPUT!? That is pretty easy. Remember cout<>. This simply is used to get input. #include void main() { int thisisanumber; cout<<"Please enter a number:"; cin>>thisisanumber; cout<> and int. int is basically a keyword that declares a variable to be an integer. Other types include char, unsigned char, float, long, double. These define characters, floating point decimals, long integers, and double floats, which go out farther. These will be used in other programs. The cin>> basically says that it should put in thisisanumber whatever the user types in. If it is not a number, the next output will be kind of weird. Then cout<< uses no quotes to print a variable, this means to print a variable, if it was as-is in quotes then it would print on the screen a string "thisisanumber". Don't forget to end functions and declarations with the semi-color(;). Otherwise you will get an error. They can be very tough to track down too. Now is about the time to learn something about variables. I have talked about declaring them, but what good is that if you don't know how to use them. Here goes: *, -, +, /, =, ==, are all operators used on numbers, these are the simple ones, if you want ore info on any of this, by the way, e-mail me at lallain@concentric.net. The * multiplies, the - subtracts, the +( adds, the = assigns the value on the right to the one on the left: a=3 means that 3 will slide over to be the value stored in a. The == is a comparison checker. a=3; a==3; This gives a the value of 3, and then sees if it has the value of three. This could be use in an if statement. DONT FORGET TO DECLARE VARIABLES. two otehr things used as comparisons are the < and > they do what they do in school check to see if it is great than or less than. To see something like greater or equal too then use >=. This is useful in some stuff I will cover next week. Note: My homepage is http://www.cprogramming.com. My email is lallain@concentric.net. Please email me with comments and or suggestions. If you want to use this on your own site please email me and add a link to http://www.cprogramming.com. Thanks :)