(New page: 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<br>• Exercise 1 due this co...)
 
Line 1: Line 1:
Lecture 3 – 1/17/2012
+
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)
+
In class quiz – Know 3 or more classmates, their names, hometown, interests, career goals (submitted at the end of class)  
  
Reminder<br>• Exercise 1 due this coming Friday (January 20th)<br>• Write Programs in EE206<br>• Check blackboard everyday<br>• Submit your signature on the class policy sheet given the first day of class<br>• Office Hours:<br>o Tuesday and Friday after class in MSEE222, open door policy. You can discuss any topic.
+
Reminder<br>• Exercise 1 due this coming Friday (January 20th)<br>• Write Programs in EE206<br>• Check blackboard everyday<br>• Submit your signature on the class policy sheet given the first day of class<br>• Office Hours:<br>o Tuesday and Friday after class in MSEE222, open door policy. You can discuss any topic.  
  
Today’s Programs<br>• Review of simple C programs<br>• Programming in Linux<br>• Maze files and rules<br>• Arc and argv<br>• Program to read characters in a file<br>• Function calls<br>• Practice how to write a program that can find 26 English characters and tell which ones appear the most often (ignore cases)<br>• Challenge: Write a program that can generate valid mazes
+
Today’s Programs<br>• Review of simple C programs<br>• Programming in Linux<br>• Maze files and rules<br>• Arc and argv<br>• Program to read characters in a file<br>• Function calls<br>• Practice how to write a program that can find 26 English characters and tell which ones appear the most often (ignore cases)<br>• Challenge: Write a program that can generate valid mazes  
  
In Linux…<br>• mkdir → makes a new directory (folder)<br>o EX: mkdir ECE264<br>• ls → lists the files in the directory<br>o EX: ls<br>• cd → changes the directory<br>o EX: cd Exercises<br>• File → determines what type of file you are dealing with<br>o EX: file prog1 (returns a ‘.c’ file type)<br>• emacs/vi filename.c → creates a file and puts it into a text editor of choice
+
In Linux…<br>• mkdir → makes a new directory (folder)<br>o EX: mkdir ECE264<br>• ls → lists the files in the directory<br>o EX: ls<br>• cd → changes the directory<br>o EX: cd Exercises<br>• File → determines what type of file you are dealing with<br>o EX: file prog1 (returns a ‘.c’ file type)<br>• 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
+
NOTE: Make sure never to have space in file name  
  
• What is used to compile programs?<br>o &nbsp; Linux: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gcc prog1.c -o prog1<br>o &nbsp; Translation: Compiler&nbsp;&nbsp;&nbsp;&nbsp; Human Readable&nbsp;&nbsp; Name of Output file&nbsp;&nbsp; Machine Readable
+
• What is used to compile programs?<br>o &nbsp; Linux: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gcc prog1.c -o prog1<br>o &nbsp; Translation: Compiler&nbsp;&nbsp;&nbsp;&nbsp; Human Readable&nbsp;&nbsp; Name of Output file&nbsp;&nbsp; Machine Readable  
  
o &nbsp; Linux: ./(no space)ex1 data<br>o &nbsp; Translation: Run Machine Readable and use a text file called data
+
o &nbsp; Linux: ./(no space)ex1 data<br>o &nbsp; Translation: Run Machine Readable and use a text file called data  
  
Example 1:
+
Example 1:  
  
a =1<br>b=2<br>if(a&gt;b)<br> printf(“…”);<br>a = 5
+
a =1<br>b=2<br>if(a&gt;b)<br> printf(“…”);<br>a = 5  
  
What is the value of ‘a’ here? 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<br>• Always remember to use brackets with all logic statements<br>• No “end” in C (as in MATLAB if statements)
+
• 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<br>• Always remember to use brackets with all logic statements<br>• No “end” in C (as in MATLAB if statements)  
  
Indexing<br>• In C, index always begins with 0
+
Indexing<br>• In C, index always begins with 0  
  
int arr[6];
+
int arr[6];  
  
for( c = 0; c &lt; 6; c++)<br>{<br> c will be 0,1,2,3,4,5<br>}
+
for( c = 0; c &lt; 6; c++)<br>{<br> c will be 0,1,2,3,4,5<br>}  
  
It is wrong to do the following:
+
It is wrong to do the following:  
  
int arr[6];
+
int arr[6];  
  
for( c = 0; c &lt;= 6; c++)<br>{<br> c will be 0,1,2,3,4,5,6 ERROR: INDEX OUT OF RANGE<br>}
+
for( c = 0; c &lt;= 6; c++)<br>{<br> c will be 0,1,2,3,4,5,6 ERROR: INDEX OUT OF RANGE<br>}  
  
Inputting a string<br>• scanf(“%s”, str);<br>• printf(“%s”, str);
+
Inputting a string<br>• scanf(“%s”, str);<br>• printf(“%s”, str);  
  
Maze program:<br>• Each wall is one layer thick<br>• Always one exit, one start<br>• Always one solution<br>• Pathways are on * in length
+
Maze program:<br>• Each wall is one layer thick<br>• Always one exit, one start<br>• Always one solution<br>• Pathways are on * in length  
  
argc and argv<br>• Same as for function arguments,
+
argc and argv<br>• Same as for function arguments,  
  
int add( int a , int b)
+
int add( int a , int b)  
  
• But instead,
+
• But instead,  
  
Int main ( int argc , char *argv[] )
+
Int main ( int argc , char *argv[] )  
  
(# of arguments, array of each argument)
+
(# of arguments, array of each argument)  
  
 
<br>• The first argument is always the name of the command<br>• Several spaces count only as 1 space separating the arguments<br>
 
<br>• The first argument is always the name of the command<br>• Several spaces count only as 1 space separating the arguments<br>

Revision as of 12:31, 22 January 2012

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)


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

Alumni Liaison

EISL lab graduate

Mu Qiao