='a'? DITDAH DAH_&223:DITDAHDAH_ DAH DAH; DIT DITDAHDIT_ DAH __DAH,_DIT_ __DAH DAH DITDAH DIT_+=DIT DITDAH _DIT_>='a'?DITDAH _DIT_-'a':0 DAH;}_DAH DIT DIT_DAH{__DIT DIT DIT_>3?_DAHDIT DIT_>>1 DAH:'\0'DAH;return DIT_&1?'-':'.';}__DIT DITDIT_ DAH _DAHDIT DIT_;{DIT void DAH write DIT 1,&DIT_,1 DAH;}"> ='a'? DITDAH DAH_&223:DITDAHDAH_ DAH DAH; DIT DITDAHDIT_ DAH __DAH,_DIT_ __DAH DAH DITDAH DIT_+=DIT DITDAH _DIT_>='a'?DITDAH _DIT_-'a':0 DAH;}_DAH DIT DIT_DAH{__DIT DIT DIT_>3?_DAHDIT DIT_>>1 DAH:'\0'DAH;return DIT_&1?'-':'.';}__DIT DITDIT_ DAH _DAHDIT DIT_;{DIT void DAH write DIT 1,&DIT_,1 DAH;}">
Download presentation
Presentation is loading. Please wait.
Published byPiers Patterson Modified over 8 years ago
1
CS 241 Section Week #1
2
About Sections Each week: – We’ll spend additional time on topics that the instructors feel should be reviewed. – We’ll prepare you for the upcoming homework or MP submissions. – We’ll provide extra review/guidance for upcoming exams.
3
C can be Ugly #defineDIT( #defineDAH) #define__DAH++ #define DITDAH* #defineDAHDITfor #defineDIT_DAHmalloc #define DAH_DITgets #define_DAHDITchar _DAHDIT _DAH_[]="ETIANMSURWDKGOHVFaLaPJBXCYZQ b54a3d2f16g7c8a90l?e'b.s;i,d:" ;mainDIT DAH{_DAHDIT DITDAH_DIT,DITDAH DAH_,DITDAH DIT_, DITDAH_DIT_,DITDAH DIT_DAH DIT DAH,DITDAHDAH_DIT DIT DAH;DAHDIT DIT _DIT=DIT_DAHDIT 81 DAH,DIT_=_DIT __DAH;_DIT==DAH_DITDIT _DIT DAH;__DIT DIT'\n'DAH DAHDAHDIT DIT DAH_=_DIT;DITDAH DAH_;__DITDITDITDAH _DIT_?_DAH DITDITDAH DIT_ DAH:'?'DAH,__DIT DIT' 'DAH,DAH_ __DAHDAH DAHDIT DIT DITDAHDIT_=2,_DIT_=_DAH_; DITDAH _DIT_&&DIT DITDAH _DIT_!=DITDITDAH DAH_>='a'? DITDAH DAH_&223:DITDAHDAH_ DAH DAH; DIT DITDAHDIT_ DAH __DAH,_DIT_ __DAH DAH DITDAH DIT_+=DIT DITDAH _DIT_>='a'?DITDAH _DIT_-'a':0 DAH;}_DAH DIT DIT_DAH{__DIT DIT DIT_>3?_DAHDIT DIT_>>1 DAH:'\0'DAH;return DIT_&1?'-':'.';}__DIT DITDIT_ DAH _DAHDIT DIT_;{DIT void DAH write DIT 1,&DIT_,1 DAH;}
4
C can be Ugly #defineDIT( #defineDAH) #define__DAH++ #define DITDAH* #defineDAHDITfor #defineDIT_DAHmalloc #define DAH_DITgets #define_DAHDITchar _DAHDIT _DAH_[]="ETIANMSURWDKGOHVFaLaPJBXCYZQ b54a3d2f16g7c8a90l?e'b.s;i,d:" ;mainDIT DAH{_DAHDIT DITDAH_DIT,DITDAH DAH_,DITDAH DIT_, DITDAH_DIT_,DITDAH DIT_DAH DIT DAH,DITDAHDAH_DIT DIT DAH;DAHDIT DIT _DIT=DIT_DAHDIT 81 DAH,DIT_=_DIT __DAH;_DIT==DAH_DITDIT _DIT DAH;__DIT DIT'\n'DAH DAHDAHDIT DIT DAH_=_DIT;DITDAH DAH_;__DITDITDITDAH _DIT_?_DAH DITDITDAH DIT_ DAH:'?'DAH,__DIT DIT' 'DAH,DAH_ __DAHDAH DAHDIT DIT DITDAHDIT_=2,_DIT_=_DAH_; DITDAH _DIT_&&DIT DITDAH _DIT_!=DITDITDAH DAH_>='a'? DITDAH DAH_&223:DITDAHDAH_ DAH DAH; DIT DITDAHDIT_ DAH __DAH,_DIT_ __DAH DAH DITDAH DIT_+=DIT DITDAH _DIT_>='a'?DITDAH _DIT_-'a':0 DAH;}_DAH DIT DIT_DAH{__DIT DIT DIT_>3?_DAHDIT DIT_>>1 DAH:'\0'DAH;return DIT_&1?'-':'.';}__DIT DITDIT_ DAH _DAHDIT DIT_;{DIT void DAH write DIT 1,&DIT_,1 DAH;} Especially when you try! (More examples at www.ioccc.org)
5
Topics This Section SVN C Code Examples in Real Life Programming Tools
6
Subversion What it is Collaboration tool for large projects Good at Code Backups Efficient - Uses diff's for backup compression A good learning block for other version control systems (git, etc.)
7
Subversion What it is not File system backup (bad at binaries) Concurrent access tool (not google docs) Good at merging lots of changes (commit often)
8
Try it! svn checkout https://subversion.ews.illinois.edu/svn/sp11- cs241/NETID/ svn If you have already checked out the repository, run `svn update` inside the directory
9
Try it! cd ~/svn (what does ~ mean) echo “this file holds my idea” > idea ls && svn add idea(what does && do) svn status svn commit -m “my first big idea”
10
Try it! Edit the file idea and save Commit the changes (Do you remember the command) Oh no, you ruined your first idea and want to go back!
11
Going back svn log svn up (short for?) svn log svn update -rXX
12
SVN Conclusion – Learn it – Love it – Hate it
13
C examples Go to ~/svn/ds/ds1 Time for some real fun! Open ds1.c using your favorite editor
14
Fun Part #1 void problem1(){ char str[7]="abc"; strcat(str,"def"); printf("%s",str); } //Issues ?
15
Fun Part #1 Are you ready for the answers on the next slide? Did you use the manpages for strcat?
16
Fun Part #1 #include //strcat void problem1(){ char str[7]; //avoid ptr to static mem strcat(str,"abc"); strcat(str,"def"); printf("%s",str); }
17
Test gcc ds.c What is binary called? Does it work? Uncomment Problem2
18
Fun Part #2 void problem2(){ char *str; for(int i=0;i<42;i+1) str = malloc( sizeof(char)); if( factorial(i,str) ){ //Error return 1; } printf("%d : %s\n",str,i); } int factorial(int num, const char* answer){ while(num >= 0){ num *= --num; sprintf(answer,"%d",num); }
19
Fun Part #2 How many bugs can you find? Once you are confident test your program
20
Fun Part #2 Are you ready for the answers? Try running `valgrind a.out`
21
Fun Part #2 constant int maxFieldSize=20 void problem2(){ char *str; int i; constant int theAnswer = 42; str = malloc( sizeof(char)*(maxFieldSize) ); for(i=0;i<theAnswer;i++){ if( factorial(i,str) ){ //Error printf(“factorial failed\n”); exit(1); } printf("%d : %s\n",i,str); } int factorial(int num, char* answer){ while(num > 0){ num *= num--; snprintf(answer,maxFieldSize,"%d",num); }
22
Questions? As a challenge see if you can optimize factorial for subsequent accesses - make sure that it still works for the general case
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.