<?xml version="1.0" encoding="UTF-8"?>
<!--Generated by Squarespace Site Server v5.11.81 (http://www.squarespace.com/) on Fri, 24 Feb 2012 11:05:08 GMT--><rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"><channel><title>CS133C</title><link>http://www.joeparis.net/cs133c/</link><description></description><lastBuildDate>Thu, 23 Feb 2012 02:09:31 +0000</lastBuildDate><copyright></copyright><language>en-US</language><generator>Squarespace Site Server v5.11.81 (http://www.squarespace.com/)</generator><item><title>Assignment 5</title><category>assignment</category><dc:creator>Joe Paris</dc:creator><pubDate>Thu, 23 Feb 2012 02:04:18 +0000</pubDate><link>http://www.joeparis.net/cs133c/2012/2/22/assignment-5.html</link><guid isPermaLink="false">377646:13514565:15151065</guid><description><![CDATA[<p>Read <strong>Allocated Memory: malloc() and free()</strong>, pages 480&ndash;485 (stop before <strong>Dynamic Memory Allocation and Variable-Length Arrays</strong>). Then read Chapter 13. Send me your questions by 5:00 Sunday, Feb. 26.</p>]]></description><wfw:commentRss>http://www.joeparis.net/cs133c/rss-comments-entry-15151065.xml</wfw:commentRss></item><item><title>Lab 3 switch Statement Derivation</title><dc:creator>Joe Paris</dc:creator><pubDate>Fri, 17 Feb 2012 17:28:30 +0000</pubDate><link>http://www.joeparis.net/cs133c/2012/2/17/lab-3-switch-statement-derivation.html</link><guid isPermaLink="false">377646:13514565:15075543</guid><description><![CDATA[<pre class="brush:c">char input[] = "SSSWILTECH1\1\11W\1WALLMP1";

main()
{
  int i, c;
  for( i=2; (c=input[i])!='\0'; i++ ) {
    switch(c) {
      case 'a':   putchar('i'); continue;
      case '1':   break;
      case 1:     while( (c=input[++i])!='\1' &amp;&amp; c!='\0' );
      case 9:     putchar('S');
      case 'E':
      case 'L':   continue;
      default:    putchar(c);
                  continue;
    }
    putchar(' ');
  }
  putchar('\n');
}</pre>
<p>The explanation:</p>
<dl class="codeExplaination"> <dt>char input[] = "SSSWILTECH1\1\11W\1WALLMP1"</dt> <dd>The character array <code>input</code> is initialized to the character string <code>"SSS...MP1"</code>.</dd> <dt>for( i=2; (c=input[2])!='\0';</dt> <dd><code>c</code> takes character values from <code>input</code> beginning at the third character.</dd> <dt>switch('S')</dt> <dd>The first time through the <code>switch</code> statement <code>c='S'</code>.</dd> <dt>default: putchar('S');</dt> <dd>The <code>default</code> case is taken since none of the cases match <code>'S'</code>. <code>S</code> is printed/</dd> <dt>continue</dt> <dd>The <code>continue</code> statement forces the next iteration of the innermost enclosing loop; in this case, the <code>for</code> loop. Notice that the <code>continue</code> effectively is a branch to the reinitialization expression of the <code>for</code>.</dd> <dt>for( ; c=input[3])!='\0'; i++) {</dt> <dd><code>c</code> gets the fourth character from <code>input</code>.</dd> <dt>switch('W')</dt> <dd><code>c='W'</code></dd> <dt>default: putchar('W'); continue</dt> <dd>As before, <code>W</code> is printed.</dd> <dt>...</dt> <dd>Similarly for <code>i=4</code>, <code>c='I'</code>.</dd> <dt>switch('L') {</dt> <dd><code>i=5</code>, <code>c='L'</code>.</dd> <dt>case 'L': continue</dt> <dd>The <code>'L'</code> case is taken, nothing is printed.</dd> <dt><code>i</code>=5, <code>c</code>='L'</dt> <dd>Nothing is printed.</dd> <dt><code>i</code>=6, <code>c</code>='T'</dt> <dd><code>T</code> is printed.</dd> <dt><code>i</code>=7, <code>c</code>='E'</dt> <dd>Nothing is printed.</dd> <dt><code>i</code>=8, <code>c</code>='C'</dt> <dd><code>C</code> is printed.</dd> <dt><code>i</code>=9, <code>c</code>='H'</dt> <dd><code>H</code> is printed.</dd> <dt>switch('1') {</dt> <dd><code>i=10</code>, <code>c='1'</code></dd> <dt>case '1': break</dt> <dd>The <code>break</code> statement forces an exit from the innermost enclosing loop or <code>switch</code>. In this case it effects a branch to the statement following the <code>switch</code>.</dd> <dt>putchar(' ')</dt> <dd>A space is printed.</dd> <dt>for( ; (c=input[11])!='\0'; i++) {</dt> <dd>Back to the top of the <code>for</code> loop.</dd> <dt>switch('\1') {</dt> <dd>The character constant <em>'\n'</em>, where <em>n</em> is up to three <strong>octal</strong> digits, yields a character with the <strong>octal</strong> value <em>n</em>. For example, <code>\0</code> yields the ASCII character <code>null</code> and <code>\101</code> the character <code>A</code>.</dd> <dt>case 1:</dt> <dd>Case labels may be either character or integer constants. <code>\1</code> matches  since C automatically coerces <code>char</code> to <code>int</code>.</dd> <dt>while( (c=input[++i])!='\1' &amp;&amp; c!='\0' );</dt> <dd>The exit condition for the <code>while</code> is either <code>c=='\1'</code> or end of string. Each time the <code>while</code> test is made, <code>i</code> is incremented by , thus the loop advances <code>i</code> through the characters of <code>input</code> until either the next <code>'\1'</code> character or the end of the string.</dd>
<p>In the while loop:</p>
<dt><code>i=12</code>, <code>c='\11'</code>;</dt> <dd>Nothing is printed.</dd> <dt><code>i=13</code>, <code>c='W'</code>;</dt> <dd>Nothing is printed.</dd> <dt><code>i=14</code>, <code>c='\1'</code>;</dt> <dd>The <code>while</code> loop terminates.</dd> <dt>case 9: putchar('S')</dt> <dd>The statements from each case follow one another directly; there is no implied break between cases. Case 9 follows case 1. <code>S</code> is printed.</dd> <dt>case 'E': case 'L': continue</dt> <dd>Cases <code>'E'</code> and <code>'L'</code> follow case 9.</dd> <dt>for( ; (c=input[15]); i++) {</dt> <dd>Again, back to the top of the <code>for</code> loop.</dd>
<p>In the for loop:</p>
<dt><code>i=15</code>, <code>c='W'</code>;</dt> <dd><code>W</code> is printed.</dd> <dt><code>i=16</code>, <code>c='A'</code>;</dt> <dd><code>A</code> is printed.</dd> <dt><code>i=17</code>, <code>c='L'</code>;</dt> <dd>Nothing is printed.</dd> <dt><code>i=18</code>, <code>c='L'</code>;</dt> <dd>Nothing is printed.</dd> <dt><code>i=19</code>, <code>c='M'</code>;</dt> <dd><code>M</code> is printed.</dd> <dt><code>i=20</code>, <code>c='P'</code>;</dt> <dd><code>P</code> is printed.</dd> <dt><code>i=21</code>, <code>c='1'</code>;</dt> <dd>A space is printed.</dd> <dt><code>i=22</code>, <code>c='\0'</code>;</dt> <dd>The <code>for</code> loop terminates.</dd> <code>putchar('\n')</code> </dl>
<p>If you think the switch about was hard to read, you may want to visit the web site for the <em><a class="offsite-link-inline" href="http://www.ioccc.org/years-spoiler.html" target="_blank">The International Obfuscated C Code Contest</a></em>. Here's a couple of examples of what you can find there...</p>
<p>This one-line program displays a 7-segment digital clock showing the time that the program was compiled.</p>
<pre class="brush:c">main(_){_^448&amp;&amp;main(-~_);putchar(--_%64?32|-~7[__TIME__-_/8%8]["&gt;'txiZ^(~z?"-48]&gt;&gt;";;;====~$::199"[_*2&amp;8|_/64]/(_&amp;2?1:8)%8&amp;1:10);}</pre>
<p>The following program (along with some needed support files availalbe on the IOCCC web site is a complete 8080 emulator.</p>
<pre class="brush:c">                               #include 
           #define n(o,p,e)=y=(z=a(e)%16 p x%16 p o,a(e)p x p o),h(
                                #define s 6[o]
             #define p z=l[d(9)]|l[d(9)+1]&lt;&lt;8,1&lt;(9[o]+=2)||++8[o]
                                #define Q a(7)
           #define w 254&gt;(9[o]-=2)||--8[o],l[d(9)]=z,l[1+d(9)]=z&gt;&gt;8
                               #define O )):((
                  #define b (y&amp;1?~s:s)&gt;&gt;"\6\0\2\7"[y/2]&amp;1?0:(
                               #define S )?(z-=
                    #define a(f)*((7&amp;f)-6?&amp;o[f&amp;7]:&amp;l[d(5)])
                               #define C S 5 S 3
                       #define D(E)x/8!=16+E&amp;198+E*8!=x?
                             #define B(C)fclose((C))
                       #define q (c+=2,0[c-2]|1[c-2]&lt;&lt;8)
                          #define m x=64&amp;x?*c++:a(x),
                         #define A(F)=fopen((F),"rb+")
                    unsigned char o[10],l[78114],*c=l,*k=l
                          #define d(e)o[e]+256*o[e-1]
#define h(l)s=l&gt;&gt;8&amp;1|128&amp;y|!(y&amp;255)*64|16&amp;z|2,y^=y&gt;&gt;4,y^=y&lt;&lt;2,y^=~y&gt;&gt;1,s|=y&amp;4
+64506; e,V,v,u,x,y,z,Z; main(r,U)char**U;{

     { { { } } }       { { { } } }       { { { } } }       { { { } } }
    { { {   } } }     { { {   } } }     { { {   } } }     { { {   } } }
   { { {     } } }   { { {     } } }   { { {     } } }   { { {     } } }
   { { {     } } }   { { {     } } }   { { {     } } }   { { {     } } }
   { { {     } } }   { { {     } } }   { { {     } } }   { { {     } } }
    { { {   } } }    { { {     } } }    { { {   } } }    { { {     } } }
      { { ; } }      { { {     } } }      { { ; } }      { { {     } } }
    { { {   } } }    { { {     } } }    { { {   } } }    { { {     } } }
   { { {     } } }   { { {     } } }   { { {     } } }   { { {     } } }
   { { {     } } }   { { {     } } }   { { {     } } }   { { {     } } }
   { { {     } } }   { { {     } } }   { { {     } } }   { { {     } } }
    { { {   } } }     { { {   } } }     { { {   } } }     { { {   } } }
     { { { } } }       { { { } } }       { { { } } }       { { { } } }

                                   for(v A((u A((e A((r-2?0:(V A(1[U])),"C")
),system("stty raw -echo min 0"),fread(l,78114,1,e),B(e),"B")),"A")); 118-(x
=*c++); (y=x/8%8,z=(x&amp;199)-4 S 1 S 1 S 186 S 2 S 2 S 3 S 0,r=(y&gt;5)*2+y,z=(x&amp;
207)-1 S 2 S 6 S 2 S 182 S 4)?D(0)D(1)D(2)D(3)D(4)D(5)D(6)D(7)(z=x-2 C C C C
C C C C+129 S 6 S 4 S 6 S 8 S 8 S 6 S 2 S 2 S 12)?x/64-1?((0 O a(y)=a(x) O 9
[o]=a(5),8[o]=a(4) O 237==*c++?((int (*)())(2-*c++?fwrite:fread))(l+*k+1[k]*
256,128,1,(fseek(y=5[k]-1?u:v,((3[k]|4[k]&lt;&lt;8)&lt;&lt;7|2[k])&lt;&lt;7,Q=0),y)):0 O y=a(5
),z=a(4),a(5)=a(3),a(4)=a(2),a(3)=y,a(2)=z O c=l+d(5) O y=l[x=d(9)],z=l[++x]
,x[l]=a(4),l[--x]=a(5),a(5)=y,a(4)=z O 2-*c?Z||read(0,&amp;Z,1),1&amp;*c++?Q=Z,Z=0:(
Q=!!Z):(c++,Q=r=V?fgetc(V):-1,s=s&amp;~1|r&lt;0) O++c,write(1,&amp;7[o],1) O z=c+2-l,w,
c=l+q O p,c=l+z O c=l+q O s^=1 O Q=q[l] O s|=1 O q[l]=Q O Q=~Q O a(5)=l[x=q]
,a(4)=l[++x] O s|=s&amp;16|9159?Q+=96,1:0,y=Q,h(s&lt;&lt;8)
O l[x=q]=a(5),l[++x]=a(4) O x=Q%2,Q=Q/2+s%2*128,s=s&amp;~1|x O Q=l[d(3)]O x=Q  /
128,Q=Q*2+s%2,s=s&amp;~1|x O l[d(3)]=Q O s=s&amp;~1|1&amp;Q,Q=Q/2|Q&lt;&lt;7 O Q=l[d(1)]O s=~1
&amp;s|Q&gt;&gt;7,Q=Q*2|Q&gt;&gt;7 O l[d(1)]=Q O m y n(0,-,7)y) O m z=0,y=Q|=x,h(y) O m z=0,
y=Q^=x,h(y) O m z=Q*2|2*x,y=Q&amp;=x,h(y) O m Q n(s%2,-,7)y) O m Q n(0,-,7)y)  O
m Q n(s%2,+,7)y) O m Q n(0,+,7)y) O z=r-8?d(r+1):s|Q&lt;&lt;8,w O p,r-8?o[r+1]=z,r
[o]=z&gt;&gt;8:(s=~40&amp;z|2,Q=z&gt;&gt;8) O r[o]--||--o[r-1]O a(5)=z=a(5)+r[o],a(4)=z=a(4)
+o[r-1]+z/256,s=~1&amp;s|z&gt;&gt;8 O ++o[r+1]||r[o]++O o[r+1]=*c++,r[o]=*c++O z=c-l,w
,c=y*8+l O x=q,b z=c-l,w,c=l+x) O x=q,b c=l+x) O b p,c=l+z) O a(y)=*c++O r=y
,x=0,a(r)n(1,-,y)s&lt;&lt;8) O r=y,x=0,a(r)n(1,+,y)s&lt;&lt;8))));
system("stty cooked echo"); B((B((V?B(V):0,u)),v)); }</pre>]]></description><wfw:commentRss>http://www.joeparis.net/cs133c/rss-comments-entry-15075543.xml</wfw:commentRss></item><item><title>Assignment 4</title><category>assignment</category><dc:creator>Joe Paris</dc:creator><pubDate>Thu, 16 Feb 2012 04:42:22 +0000</pubDate><link>http://www.joeparis.net/cs133c/2012/2/15/assignment-4.html</link><guid isPermaLink="false">377646:13514565:15056857</guid><description><![CDATA[<p>Complete the following Programming Exercises starting on page 301 of your book: #2, #3, #8. Complete the following Programming Exercises staring on page 345 of your book: #6 and #7. You may do #8 on page 345 for extra credit.</p>
<p>Due Wednesday, Feb. 22.</p>
<p>Read Chapter 10 for class on Wednesday. E-mail me your questions no later than noon on Tuesday, Feb. 21.</p>
<p>You should expect a quiz on Wedneday.</p>]]></description><wfw:commentRss>http://www.joeparis.net/cs133c/rss-comments-entry-15056857.xml</wfw:commentRss></item><item><title>Lab 3</title><category>lab</category><dc:creator>Joe Paris</dc:creator><pubDate>Tue, 14 Feb 2012 22:15:49 +0000</pubDate><link>http://www.joeparis.net/cs133c/2012/2/14/lab-3.html</link><guid isPermaLink="false">377646:13514565:15025798</guid><description><![CDATA[<p><a href="http://www.joeparis.net/storage/data_files/12_winter/cs133c/lab-3.pdf" target="_blank">Lab 3</a></p>
<p><a href="http://www.joeparis.net/storage/data_files/12_winter/cs133c/defs.h">defs.h</a></p>]]></description><wfw:commentRss>http://www.joeparis.net/cs133c/rss-comments-entry-15025798.xml</wfw:commentRss></item><item><title>FILE Sample Code</title><category>in-class demo</category><category>sample code</category><dc:creator>Joe Paris</dc:creator><pubDate>Tue, 14 Feb 2012 18:28:09 +0000</pubDate><link>http://www.joeparis.net/cs133c/2012/2/14/file-sample-code.html</link><guid isPermaLink="false">377646:13514565:15034774</guid><description><![CDATA[<pre class="brush:c">#include 
#include 

int main(int argc, char const *argv[])
{
    int ch;
    FILE *fp; // ignore the woman behind the curtain
    char fname[50];

    printf("Enter the name of the file: ");
    scanf("%s", fname);
    fp = fopen(fname, "r");
    if(!fp)
    {
        printf("Failed to open file %s.", fname);
        return -1;
    }

    while((ch = getc(fp)) != EOF)
        putchar(ch);

    fclose(fp);

    return 0;
}</pre>]]></description><wfw:commentRss>http://www.joeparis.net/cs133c/rss-comments-entry-15034774.xml</wfw:commentRss></item><item><title>Project Requirements</title><category>project</category><dc:creator>Joe Paris</dc:creator><pubDate>Sun, 05 Feb 2012 01:05:17 +0000</pubDate><link>http://www.joeparis.net/cs133c/2012/2/4/project-requirements.html</link><guid isPermaLink="false">377646:13514565:14876450</guid><description><![CDATA[<div>You program must:</div>
<div>
<ul>
<li>Contain &gt; 250 (actual) LOC</li>
<li>Interactive, getting input from user</li>
<li>Store data in a struct</li>
<li>Maintain a linked list of data used in the program</li>
<li>Allow for searching, inserting, and removal of data during run time</li>
<li>Save program data to file</li>
<li>Read program data from file provided via command line</li>
</ul>
</div>
<div>Submit a written project proposal by Feb 13 for approval.</div>]]></description><wfw:commentRss>http://www.joeparis.net/cs133c/rss-comments-entry-14876450.xml</wfw:commentRss></item><item><title>Sizes</title><category>assignment</category><dc:creator>Joe Paris</dc:creator><pubDate>Thu, 02 Feb 2012 15:32:26 +0000</pubDate><link>http://www.joeparis.net/cs133c/2012/2/2/sizes.html</link><guid isPermaLink="false">377646:13514565:14840459</guid><description><![CDATA[<p>As I mentioned in class, I'd like you all to try running the following code on as many different platforms as you can and note the sizes of the various types. What differences do you find?</p>
<p>sizes.c.</p>
<pre class="brush:c">#include &lt;stdio.h&gt;

int main(int argc, char const *argv[])
{
    printf("%19s:%3d\n", "long double", sizeof(long double));
    printf("%19s:%3d\n", "double", sizeof(double));
    printf("%19s:%3d\n", "float", sizeof(float));
    printf("%19s:%3d\n", "unsigned long long", sizeof(unsigned long long));
    printf("%19s:%3d\n", "long long", sizeof(long long));
    printf("%19s:%3d\n", "unsigned long", sizeof(unsigned long));
    printf("%19s:%3d\n", "long", sizeof(long));
    printf("%19s:%3d\n", "unsigned int", sizeof(unsigned int));
    printf("%19s:%3d\n", "unsigned short", sizeof(unsigned short));
    printf("%19s:%3d\n", "int", sizeof(int));
    printf("%19s:%3d\n", "char", sizeof(char));
    printf("%19s:%3d\n", "signed char", sizeof(signed char));
    printf("%19s:%3d\n", "short", sizeof(short));
        
    return 0;
}</pre>]]></description><wfw:commentRss>http://www.joeparis.net/cs133c/rss-comments-entry-14840459.xml</wfw:commentRss></item><item><title>Labs 1 &amp; 2 Handouts</title><category>lab</category><dc:creator>Joe Paris</dc:creator><pubDate>Wed, 01 Feb 2012 01:00:40 +0000</pubDate><link>http://www.joeparis.net/cs133c/2012/1/31/labs-1-2-handouts.html</link><guid isPermaLink="false">377646:13514565:14790989</guid><description><![CDATA[<p>Some of you have been asking for copies of the lab handouts. Here's they are.</p>
<p><a href="http://www.joeparis.net/storage/data_files/12_winter/cs133c/lab-1.pdf" target="_blank">Lab 1</a></p>
<p><a href="http://www.joeparis.net/storage/data_files/12_winter/cs133c/lab-2.pdf" target="_blank">Lab 2</a></p>]]></description><wfw:commentRss>http://www.joeparis.net/cs133c/rss-comments-entry-14790989.xml</wfw:commentRss></item><item><title>Help!</title><category>announcement</category><dc:creator>Joe Paris</dc:creator><pubDate>Tue, 31 Jan 2012 22:40:40 +0000</pubDate><link>http://www.joeparis.net/cs133c/2012/1/31/help.html</link><guid isPermaLink="false">377646:13514565:14813446</guid><description><![CDATA[<p><span>Several of you have asked if there are any tutors that can help you with the material we are covering. In fact, we have an open lab in MKH-105 every Tuesday/Thursday from 11:20-1:00 and Friday from 10:00-2:00 that is staffed by folks who are more than happy to help you out. I&nbsp;</span><strong>strongly</strong><span>&nbsp;encourage you to go, even if you feel that you have a handle on the material. There's always more you can learn and working together with your classmates will be rewarding, I promise.</span></p>]]></description><wfw:commentRss>http://www.joeparis.net/cs133c/rss-comments-entry-14813446.xml</wfw:commentRss></item><item><title>Assignment 3</title><category>assignment</category><dc:creator>Joe Paris</dc:creator><pubDate>Mon, 30 Jan 2012 23:00:21 +0000</pubDate><link>http://www.joeparis.net/cs133c/2012/1/30/assignment-3.html</link><guid isPermaLink="false">377646:13514565:14790779</guid><description><![CDATA[<p>Yay! A <a href="http://www.joeparis.net/storage/data_files/12_winter/cs133c/programming_assignment-3.pdf" target="_blank">new assignment</a>! Due Monday, Feb. 6 at the beginning of class. Here's the <a href="http://www.joeparis.net/storage/data_files/12_winter/cs133c/numbers.dat">numbers.dat</a> file you will need for problem 3. &nbsp;Remember, code dropped electronically through the <a href="http://www.joeparis.net/cs133c-dropbox/" target="_blank">web site</a> and hard copy to me for comment.</p>
<p>For Wednesday, Feb 1 you need to read Chapter 5 and submit your questions via e-mail. Much of this chapter will be very familiar, but there are some C-specific twists you should know about. Your e-mail must have the following subject line:</p>
<p><em>your name, your class, chapter X questions</em></p>
<p>For example:</p>
<p><em>Joe Paris, CS133C, chapter 5 questions</em></p>]]></description><wfw:commentRss>http://www.joeparis.net/cs133c/rss-comments-entry-14790779.xml</wfw:commentRss></item></channel></rss>
