Up to Main Page
Back to Previous Lecture
Forward to Next Lecture
This topic introduces you to the type of data that computers use. Most of the example programs will be using integer numbers, but many of them could be done with floating point numbers as well.
This little program add.c, simply adds two numbers together and displays the result. While somewhat interesting, it is unlikely that you would actually use such a program, when all you really needed was a calculator. :^)
In case you were wondering, atoi stands for "ASCII to Integer". Likewise, atof stands for "ASCII to Float".
ASCII is the code that most computers use to represent characters. Since everything inside the computer is a number, there must be numbers to represent the various characters. You can examine this code in the Appendix of the text book.
Too see what is required to get a floating point value from the user, look at the program getfloat.c.
The program addnums.c shows you how to get two numbers from the user, add them together and display their sum. A floating point version is also available in addfloat.c.
The program getinfo.c shows you how to get various information from the user. In this program, we get their first and last name, as well as their age. This program uses the gets() and atoi() functions, which is they way I recommend.
The program scanf.c shows you how to do the same thing using scanf, but I caution you to not get in the habit of using scanf. It might seem that the gets() and atoi() is harder and more complicated, but not when you consider the problems you can get into with scanf.
Up to Main Page
Back to Previous Lecture
Forward to Next Lecture