Overview
I hope everyone had a restful Thanksgiving holiday and you've come back ready to start programming in C! After programming in binary, and then assembly langauge, I think you will greatly appreciate the usability and power that a higher level structured programming language like C gives us.
This will be an opportunity for those of you who struggled with the previous projects to start fresh!
Friday and Monday, December 5th and 8th
Classwork
It's that time again, NVCC Course Evaluations! Please visit https://nova.direct.iota360.cc, enter your VCCS email and your NVCC student number and complete your evaluations. NVCC will provide me with regular updates as to your participation rates, so I will nag relentlessly until you get this done :-)
We'll begin class today by checking the running versions of CLISUM
that you wrote for homework.
Next we'll look at file I/O. Using The Buffered File I/O Functions section on page 133 of the BDS C User's Guide, I was able to write COPY.C.
Wow, this was so much easier than it was in 8080 assembly language, right? Abstraction rocks!
One caution: last year I changed the c variable in this program
from int to char and it broke it. It turns out that
EOF is not a character!
That link is to a wonderful blog post, by the way, well worth a quick reading.
Homework / Evaluation
Rewrite the disk access program you wrote as your final project with assembly language in C. Come to next class ready to show it running on your computer.
Wednesday and Thursday, December 3rd and 4th
Classwork
Since many of you were not ready with your disk I/O programs, and I ended up with only a single application of what I was hoping for (batch processing of lines of input with a text file containing corresponding lines of output), we needed to postpone our plans to start C by a day. We'll find a time to share presentations of the working assembly programs later, but for now just email them to me and let me confirm they work before we share them in class.
Today we will compile (we're not assembling any more baby! ;-) our first
C program on CP/M using BDS C, the infamous helloworld.c.
Here's what to do:
- Create a file named
CSTUFF.SUBon yourCdrive with the following contents:PIP $1:=C:CC.COM PIP $1:=C:CC2.COM PIP $1:=C:CLINK.COM PIP $1:=C:C.CCC PIP $1:=C:DEFF.CRL PIP $1:=C:DEFF2.CRL PIP $1:=C:STDIO.H
Now, if you want to use drive
Dfor compiling C programs, you can switch to theAand run:submit c:cstuff D
and it will copy the 7 files you need from drive
Cto driveD. - Using your favorite text editor (
EDof course! ;-) create a file namedHELLO.Cin theDdrive with the following contents:#include <stdio.h> main() { printf("hello, world!\n"); } - Compile and link your program with:
D>CC HELLO
Finally, run your program with:
D>CLINK HELLO
Then Run:
D>HELLO
and you should see:
hello, world!
ARGS.C
The next program we'll look at reads arguments from the command line:
#include <stdio.h>
main (argc, argv)
int argc;
char **argv;
{
int i;
printf("Command line argument test\n");
for (i = 1; i < argc; i++) {
printf("%s\n", argv[i]);
}
}
Compile it and run it with:
D>args 1 2 buckle my shoe 3 4 shut the door
and see what you get.
Homework / Evaluation
You'll work individually for this first C programming assignment, since you all need to have the process down so we can continue.
Your task is to write a program named CLISUM that takes a sequence
of integer values at the CP/M command line and prints out their sum. An A
submission should gracefully handle invalid input. Sample runs might include:
D>clisum 5 15 22 8 Sum is 50 D>clisum 1 1 1 1 1 1 1 Sum is 7 D>clisum 5 15 icecream 8 OOPS! ICECREAM is not a number
In addition to ARGS.C, you should use the ndigit
discussion beginning on page 20, and the atoi discussion
beginning on page 39 of The C Programming Language as resources for this
assignment.
This assignment is due before our next class! I'll come around at the beginning of class and check you off for showing it to me running on your laptop.