Line 11: Line 11:
 
[[Image:Yuanhua 2-2.png|500x700px]]  
 
[[Image:Yuanhua 2-2.png|500x700px]]  
  
= '''Lecture (1-26-2011):'''<br> =
+
= '''Lecture&nbsp;(1-21-2011):'''<br> =
  
#include &lt;stdio.h&gt;
+
<br>Gcc –wall progl.c –o pl <br> Argument shell
  
File *fhd;<br>int numRow=0;<br>int numCol=0;<br>int col = 0;<br>int ch;
+
&gt;ls<br>&gt;-l<br>&gt;cd
 +
 
 +
int main(int argc, char* argv[])<br>}<br> int abc = 5;<br> int xyz = 10;<br> xyz = f1(abc);<br>if(abc==c)<br>{<br> …<br>}<br> Return 0;<br>}
 +
 
 +
int f1(int abc, char xyz, double stu)<br>{<br> int counter;<br> abc = 10;<br> f2(abc);<br> return -1;<br>}
 +
 
 +
<br>void f2(int xyz)<br>{<br> int abc = -1;<br> <br>}
 +
 
 +
Stack vs. Heap!<br>order of first in last out<br>counter /////<br>double 0.5<br>xyz char ‘a’<br>abc (main) 5<br> L1<br>xyz (int) 10<br>abc (from f1) 5
 +
 
 +
<br>frame <br>abc -1<br>xyz 10<br>L2
 +
 
 +
Regarding maze traversal:<br>know your location<br>track your steps  go back to last intersection<br>map your file<br>priority list <br>detect exit (confirm there is one)<br>read maze
 +
 
 +
Height is unlimited<br>Max will not exceed 80 for width<br>(0,0) (0,1)<br>* * * *&nbsp; *<br>* &nbsp; &nbsp; &nbsp; &nbsp; *<br>*&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; E<br>* &nbsp;&nbsp; * &nbsp;&nbsp; *<br>* &nbsp;&nbsp; * &nbsp;&nbsp; *<br>* * * *&nbsp; *
 +
 
 +
It can start at a intersection
 +
 
 +
(3,1) (2,3) ASCII<br>(2,1) (3,3) American<br> standard<br> code<br> for info interchange?
 +
 
 +
FILE * find = fopen(argv[1], “r”);<br>if(fhd == 0);<br>{<br> /*error*/<br>}
 +
 
 +
while(!feof(fhd))<br>{<br> int ch = fgetc(fhol);<br> ch is ‘*’;<br> ‘\n’<br>}<br>fclose(fhd)<br><br>
 +
 
 +
<br>
 +
 
 +
= '''Lecture (1-26-2011):'''<br>  =
 +
 
 +
#include &lt;stdio.h&gt;
  
 +
File *fhd;<br>int numRow=0;<br>int numCol=0;<br>int col = 0;<br>int ch;
  
 +
<br>
  
if (arg&lt;2)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp; /*error*/<br>}
+
if (arg&lt;2)<br>{<br>&nbsp;&nbsp;&nbsp;&nbsp; /*error*/<br>}  
  
fhd = fopen(argv[1]."r");<br>if(fhd==0)<br>{<br>&nbsp;&nbsp;&nbsp; /*error*/<br>}<br>&nbsp;&nbsp; while(!feof(fhd))<br>&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ch = fgetc(fhd);<br>&nbsp; &nbsp; &nbsp;&nbsp; if(ch=='\n')<br>&nbsp;&nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; numRow++;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; if(num Col&lt;col)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; numCol = col;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; col = 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; col++;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>printf("width=%d,height=%d\n",numCol,numRow);
+
fhd = fopen(argv[1]."r");<br>if(fhd==0)<br>{<br>&nbsp;&nbsp;&nbsp; /*error*/<br>}<br>&nbsp;&nbsp; while(!feof(fhd))<br>&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ch = fgetc(fhd);<br>&nbsp; &nbsp; &nbsp;&nbsp; if(ch=='\n')<br>&nbsp;&nbsp; &nbsp; &nbsp; {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; numRow++;<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; if(num Col&lt;col)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; numCol = col;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; col = 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; col++;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>printf("width=%d,height=%d\n",numCol,numRow);  
  
gcc prog.c -o prog
+
gcc prog.c -o prog  
  
We need to know the enviornment and the direction we are going to take:<br>Need to have a way to remember where we are located:
+
We need to know the enviornment and the direction we are going to take:<br>Need to have a way to remember where we are located:  
  
Pointers:<br>int x;<br>x=5
+
Pointers:<br>int x;<br>x=5  
  
Value ---&gt; 800<br>address 650y
+
Value ---&gt; 800<br>address 650y  
  
int *y;<br>/* y is a pointer to integer*/<br>y = 'x'; &lt;-- warning message<br>take x's addr
+
int *y;<br>/* y is a pointer to integer*/<br>y = 'x'; &lt;-- warning message<br>take x's addr  
  
 
*y = LHS left hand side take y's value as an adr, modify the value at that addr.
 
*y = LHS left hand side take y's value as an adr, modify the value at that addr.
  
= *y Right hand side (RHS) ---&gt; Means assign <br>Take y's value as an addr, read from that addr.
+
= *y Right hand side (RHS) ---&gt; Means assign <br>Take y's value as an addr, read from that addr.  
  
 
*y = 50;<br>y = &amp;z;<br>*y = 35; ---&gt; z = 35
 
*y = 50;<br>y = &amp;z;<br>*y = 35; ---&gt; z = 35
  
Goo mainstreet ---&gt; address<br>family Johnson ----&gt; value
+
Goo mainstreet ---&gt; address<br>family Johnson ----&gt; value  
  
int a[10];<br> ^-- 3<br>if(ch=='A')<br> ^-- 65 ascII
+
int a[10];<br> ^-- 3<br>if(ch=='A')<br> ^-- 65 ascII  
  
memory<br>one - dimension array<br>int *a;<br>a = malloc(numElem *sizeof(int));<br>^---a's value is the start addr of a piece of memory <br>a[0] = ____<br>x = a [0];<br>.<br>.<br>.<br>free(a); &lt;--- lose 50 points RELEASE THE MEMORY (Memory Leak if not there)
+
memory<br>one - dimension array<br>int *a;<br>a = malloc(numElem *sizeof(int));<br>^---a's value is the start addr of a piece of memory <br>a[0] = ____<br>x = a [0];<br>.<br>.<br>.<br>free(a); &lt;--- lose 50 points RELEASE THE MEMORY (Memory Leak if not there)  
  
Stack Heap<br>a 1000
+
Stack Heap<br>a 1000  
  
C does not specify sizeof(int)<br>Portable: Run on different machine
+
C does not specify sizeof(int)<br>Portable: Run on different machine  
  
malloc(#elem*sizeof(one elem));<br>^--- modify the value at that addr
+
malloc(#elem*sizeof(one elem));<br>^--- modify the value at that addr  
  
if(a==0)<br>{<br> /* malloc fails */<br> //if malloc fails a is 0<br>}
+
if(a==0)<br>{<br> /* malloc fails */<br> //if malloc fails a is 0<br>}  
  
you already know the size of the maze.
+
you already know the size of the maze.  
  
 
int array[numRow]; The program does not know when you compile the program!<br>
 
int array[numRow]; The program does not know when you compile the program!<br>

Revision as of 22:41, 30 April 2011

Lecture 1:

ECE264Lecture1-1.png

Yuanhua1-1.png

Lecture 2:

Yuanhua 2-1.png

Yuanhua 2-2.png

Lecture (1-21-2011):


Gcc –wall progl.c –o pl
Argument shell

>ls
>-l
>cd

int main(int argc, char* argv[])
}
int abc = 5;
int xyz = 10;
xyz = f1(abc);
if(abc==c)
{

}
Return 0;
}

int f1(int abc, char xyz, double stu)
{
int counter;
abc = 10;
f2(abc);
return -1;
}


void f2(int xyz)
{
int abc = -1;

}

Stack vs. Heap!
order of first in last out
counter /////
double 0.5
xyz char ‘a’
abc (main) 5
L1
xyz (int) 10
abc (from f1) 5


frame
abc -1
xyz 10
L2

Regarding maze traversal:
know your location
track your steps  go back to last intersection
map your file
priority list
detect exit (confirm there is one)
read maze

Height is unlimited
Max will not exceed 80 for width
(0,0) (0,1)
* * * *  *
*         *
*        E
*    *    *
*    *    *
* * * *  *

It can start at a intersection

(3,1) (2,3) ASCII
(2,1) (3,3) American
standard
code
for info interchange?

FILE * find = fopen(argv[1], “r”);
if(fhd == 0);
{
/*error*/
}

while(!feof(fhd))
{
int ch = fgetc(fhol);
ch is ‘*’;
‘\n’
}
fclose(fhd)


Lecture (1-26-2011):

  1. include <stdio.h>

File *fhd;
int numRow=0;
int numCol=0;
int col = 0;
int ch;


if (arg<2)
{
     /*error*/
}

fhd = fopen(argv[1]."r");
if(fhd==0)
{
    /*error*/
}
   while(!feof(fhd))
   {
       ch = fgetc(fhd);
       if(ch=='\n')
       {
          numRow++;
        }
        if(num Col<col)
        {
           numCol = col;
            col = 0;
         }
          col++;
      }
printf("width=%d,height=%d\n",numCol,numRow);

gcc prog.c -o prog

We need to know the enviornment and the direction we are going to take:
Need to have a way to remember where we are located:

Pointers:
int x;
x=5

Value ---> 800
address 650y

int *y;
/* y is a pointer to integer*/
y = 'x'; <-- warning message
take x's addr

  • y = LHS left hand side take y's value as an adr, modify the value at that addr.

= *y Right hand side (RHS) ---> Means assign
Take y's value as an addr, read from that addr.

  • y = 50;
    y = &z;
    *y = 35; ---> z = 35

Goo mainstreet ---> address
family Johnson ----> value

int a[10];
^-- 3
if(ch=='A')
^-- 65 ascII

memory
one - dimension array
int *a;
a = malloc(numElem *sizeof(int));
^---a's value is the start addr of a piece of memory
a[0] = ____
x = a [0];
.
.
.
free(a); <--- lose 50 points RELEASE THE MEMORY (Memory Leak if not there)

Stack Heap
a 1000

C does not specify sizeof(int)
Portable: Run on different machine

malloc(#elem*sizeof(one elem));
^--- modify the value at that addr

if(a==0)
{
/* malloc fails */
//if malloc fails a is 0
}

you already know the size of the maze.

int array[numRow]; The program does not know when you compile the program!

Alumni Liaison

EISL lab graduate

Mu Qiao