Welcome to your first Computing 1B laboratory.
gcc system to compile C programs
give command.
Once you've done this, you are free to leave the Lab Class.
In this Lab you'll be working with a number of small programs.
Create a separate directory (lab02 is a good name) using mkdir for this week's lab exercises and change to that directory.
Compile and execute this program. The following commands show what ought to happen:
% /home/cs1721/bin/dcc hello.c % ./a.out Hello, World!Note that the
dcc command doesn't print anything if the compilation is
successful.
You can check that it has produced an executable by typing ls -l and
looking for a newly-created a.out file (check the file time to see if
it really is new).
/*
* Variation of the "Hello, World" program
* Asks for your name and then greets you.
* Find the bugs, fix them, and then delete this line.
/
#include <stdio.h>
int main(void) {
char name[16]; /* string to hold name */
printf("What"s your name? ");
scanf("%15s", name)
printf("Hi there, %s!\n);
return 0;
When you attempt to compile this program you should get a number of errors:
% /home/cs1721/bin/dcc hello.c hey.c:10: warning: `/*' within comment hey.c:12: parse error before string constant hey.c:13: nondigits in number and not hexadecimal hey.c:14: stray '\' in program hey.c:14: warning: type defaults to `int' in declaration of `printf' hey.c:14: warning: data definition has no type or storage class
Find and fix these errors. The working program should behave like this:
% ./a.out What's your name? Andrew Hi there, Andrew!
Don't worry that you can't understand the entire program. It contains some C features that we haven't covered in lectures (e.g. the type of the variable name). You should know enough to fix the errors.
% ./a.out Enter first number: 3 Enter second number: 5 Sum [3..5] = 12Put your program in a file
sum.c.
Remember you saw an example of reading a value into an int variable in your tutorial.
What you need to do is: fill in the main program, get it to compile, test it on a number of examples, and then demonstrate it to your tutor.
% give cs1721 lab02 sum.c