Revision as of 11:12, 22 January 2012 by Jribeir (Talk | contribs)

Rhea Section for ECE 264 Professor Yung-Hsiang Lu, Spring 2012

Lecture 3

Lecture 3 – 1/17/2012

In class quiz – Know 3 or more classmates, their names, hometown, interests, career goals (submitted at the end of class)

Reminder • Exercise 1 due this coming Friday (January 20th) • Write Programs in EE206 • Check blackboard everyday • Submit your signature on the class policy sheet given the first day of class • Office Hours: o Tuesday and Friday after class in MSEE222, open door policy. You can discuss any topic.

Today’s Programs • Review of simple C programs • Programming in Linux • Maze files and rules • Arc and argv • Program to read characters in a file • Function calls • Practice how to write a program that can find 26 English characters and tell which ones appear the most often (ignore cases) • Challenge: Write a program that can generate valid mazes

In Linux… • mkdir → makes a new directory (folder) o EX: mkdir ECE264 • ls → lists the files in the directory o EX: ls • cd → changes the directory o EX: cd Exercises • File → determines what type of file you are dealing with o EX: file prog1 (returns a ‘.c’ file type) • emacs/vi filename.c → creates a file and puts it into a text editor of choice

NOTE: Make sure never to have space in file name

• What is used to compile programs? o Linux: gcc prog1.c -o prog1 o Translation: Compiler Human Readable Name of Output file Machine Readable

o Linux: ./(no space)ex1 data o Translation: Run Machine Readable and use a text file called data

Example 1:

a =1 b=2 if(a>b) printf(“…”); a = 5

What is the value of ‘a’ here? a = 5.

• In the statement above, it doesn’t matter what is inside the if statement because ‘a’ is later redefined to be a OUTSIDE the if statement • Always remember to use brackets with all logic statements • No “end” in C (as in MATLAB if statements)

Indexing • In C, index always begins with 0

int arr[6];

for( c = 0; c < 6; c++) { c will be 0,1,2,3,4,5 }

It is wrong to do the following:

int arr[6];

for( c = 0; c <= 6; c++) { c will be 0,1,2,3,4,5,6 ERROR: INDEX OUT OF RANGE }

Inputting a string • scanf(“%s”, str); • printf(“%s”, str);

Maze program: • Each wall is one layer thick • Always one exit, one start • Always one solution • Pathways are on * in length

argc and argv • Same as for function arguments,

int add( int a , int b)

• But instead,

Int main ( int argc , char *argv[] )

(# of arguments, array of each argument)

argv element#

0 . / a r g s \0 (What is stored in row 0)

1 d a t a \0 (What is stored in row 1)

....


• The first argument is always the name of the command • Several spaces count only as 1 space separating the arguments

Alumni Liaison

Abstract algebra continues the conceptual developments of linear algebra, on an even grander scale.

Dr. Paul Garrett