Programming in C - Address Program
If you followed the directions in the last section, you should have written a program that would print out your name and address, as if it were a mailing label. Going by the method used in the first program, your second program should look something like this:
#include <stdlib.h>
#include <stdio.h>
void main()
printf ("10425 Cherry Lane\n");
printf ("Walla Walla, Washington, 44614\n\n");
If you want, you can cut & paste the code, or ( I suggest ) type it into your your editor, make it, link it and run it. I suggest typing it, as you tend to learn more by hard coding ( repetition is the key to learning ), and you also get the added benifit of allowing yourself to debug and fix your errors. It is a good learning exercise to make mistakes and have to fix them.
Notice that in the 5th line of code, I put the \n ( escape n ) twice. The reason for this is simple. IF you wanted your program to print a bunch of labels, you wouldn't want them all bunched together. So the extra \n is to separate the first lable from a second one which might be printed in succession.
When writing code in C, C++ or Java, you have to remember that you are working with a slightly different kind of programming language. In basic or assembly, one might write a "subroutine" which will be called up multiple times to perform the same function repeatedly. In C, each "subroutine" is a completely different program, which may be called up by another program. We have to treat each program as if it is not a standalone, but a sub part of another program.
Similarly, another approach might be to create a separate program ( we might call it "space.c" ) which would generate a space between printed texts such as the one in " address.c ". Such a program might look something like this:
#include <stdlib.h>
#include <stdio.h>
void main()
If we opted to do it this way, we would have to include both these files in any program we chose to use them in.
Now on to bigger and better things.
On The Following Indicator...
(
GREEN
will indicate your current location)
|
|
1
|
2
|
3
|
|
4
|
5
|
6
|
7
|
8
|
9
|
10
|
[
ElectronicsTheory.Com
]
This Course was written by Ray Dall © All Rights Reserved.
This page and all it's content Copyright, Trademarks, Intellectual Properties
and other legal issues 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Ray Dall.
All Rights Reserved.
And for what it's worth... this page was last updated HexDate 01-11--7D1
VISITORS: