Software Engineering 265
Week 03
1"
Announcements
Attendance (attend_and_reference.html)
The"assignment"due"date"is"postponed"to"
Saturday"September"27"at"midnight"
2"
This Week
Programming in C!
C shell quick exercise
C Pointers
Arrays and Arrays of char.
Touch on sizeof() and malloc
3"
C: Introduction
Make a folder in your work space.
Write and compile a C shell program:
#include <stdio.h> // Add the std i/o library for reference
// says it will return an integer the int in front of main
int main() {
/*
Multi-line comment
*/
int a = 1;
printf(This is a number: %2d\n, a);
return(0); // note how it returns an integer!
}
4"
C: Compiling Options
To compile your source code you need to use gcc
<progname.c>
On Unix gcc produces an output file called a.out
(This is the binary)
Use the flag o <filename> to specify an
output name other than a.out:
Ex: gcc hello.c -o hello
Turn on warnings:
gcc Wall <progname.c>
5"
C: Hello World!
Now you need to run your code!
To run your code, you need to call the
binary you created
You do this by using the ./ command
./hello
or ./a.out
6"
C: Extra Notes
Strings in C are arrays of characters
Arrays are just indexed groups of things:
Index: 0 1 2 3 4 5
Data: H" e" l" l" o" \0"
If you do not specify a size of the string like
char c[6];
you will not get the end of string character \0.
7"
More examples
Copy the c programs from this weeks folder into
your work space.
We will open, examine and modify each of the
programs.
8"