1 / 21

ECS30 Discussion Section Week 2

ECS30 Discussion Section Week 2. TA's: Hyorim Yang Shizhuo Yu Yun Li University of California, Davis, CA. Office Hour This Week. Yun: Thursday 3-5 pm Friday 3-5 pm 53 Kemper hryang@ucdavis.edu szyu@ucdavis.edu yunli@ucdavis.edu. #include <stdio.h>

adanna
Download Presentation

ECS30 Discussion Section Week 2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ECS30 Discussion SectionWeek 2 TA's: Hyorim Yang Shizhuo Yu Yun Li University of California, Davis, CA

  2. Office Hour This Week Yun: Thursday 3-5 pm Friday 3-5 pm • 53 Kemper • hryang@ucdavis.edu • szyu@ucdavis.edu • yunli@ucdavis.edu

  3. #include <stdio.h> #include <stdlib.h> int main(void) { 1 int x, y; 2 scanf(“%d”, &x); 3 y = 1;//init 4 5 if (x < 0) y = -1;//--level 1 6 else //--level 1 7 if (x > 0) //--level 2 8 { 9 if (x >= 255) y = 255; //--level 3 10 } 11 else y = 0; //--level 2 12 13 printf(“y = %d\n”, y);//output }

  4. Several Comments • deadline • Directory • What professor asks(read into assignment) • What problem asks

  5. Deadline Q: Will my homework be graded if I submit it late?

  6. Directory Q: where to handin my homework • a) ecs30 • b) ecs30b • c) cs 30 • d) cs 30b

  7. What professor asks Homework #6 (4%, 0.2% Makefile, 3.8% programming) Due: Thursday, March 1st, 2012, 11:59 p.m. (hard deadline) The purpose of this assignment is to loop, call by reference, arrays, strings and very simple file I/O under C. Also, you need to use the preprocessor statements such as #ifdef and #endif to include your debugging fprintf statements. BTW, in this homework assignment, you are disallowed to use printf/scanf. You must use fprintf/fscanf instead.

  8. What professor asks (Makefile/Debugging, 0.4%) In this homework assignment, you will write two C programs to solve two different problems. In order to compile and build these four programs into executables, you will write ONE Makefile to compile and build both C programs. For both programs, you MUST include AT LEAST one debugging fprintf statement PER FUNCTION. And, you must put #ifdef and #endif around ALL the debugging statements/blocks. Finally, the flag to turn on all the debugging statements must be ECS30B_DEBUG”.

  9. What problem asks (Program #1, 2.6%) Game of Life(quoted from facebook group) If you wiki game of life, it explains it. Basically, it's a program that maps "cell growth" under specific rules which dictate their "birth and death." 1. Any live cell with fewer than two live neighbors dies, as if caused by under-population. 2. Any live cell with two or three live neighbors lives on to the next generation. 3. Any live cell with more than three live neighbors dies, as if by overcrowding. 4. Any dead cell with exactly three live neighbors becomes a live cell, as if by reproduction.

  10. What to do To complete four functions 1. int countMatrix ()// do some sum up 2. int countNeighbor ()//how to denote neighbor? 3. int GOLrule ()//if(){} 4. void nextGeneration ()//calle GOLrule() and countNeighbor()

  11. Q: What is the example excutable file cannot excute in my computer A: 1, use ls -l to check status, and use chmod to set access. 2, check your computer, 32 or 64 byte, choose the right one. Q: Other suggestion? A: Read the professor's comments (in the .c file) carefully.

  12. What problem asks (Program #2, 1.0%) Finding the longest common suffix, Project 9.8, Page 513. Write and test a functionthat finds and returns through an output parameter the longest common suffix of two words. (e.g., the longest common suffix of “procrastination” and “destination” is “stination”, of “globally” and “internally” is “ally”, and of “gloves” and “dove” is empty string)

  13. What it looks like? • Please input the first words: • Please input the second words: • The longest common suffix of these two words are: • The length of longest common suffix is : • No common suffix exits.

  14. How to consider it? • Please input the first words: • Read from input, save as char string • Please input the second words: • The longest common suffix of these two words are: • Compare from the last character, until no same character • The length of longest common suffix is : • Save these characters and count number • No common suffix exits.

  15. What's difficult? • Read from input, save as char string • How to read from input? • Compare from the last character, until no same character • How to get started from the last character? • Save these characters and count number • How to count the length

  16. To get started with my program #include <stdio.h> #include <stdlib.h> #define p2_DEBUG int main(void) { #ifdef p2_DEBUG fprintf(stdout,"Here is something you want to debug with.\n"); #endif return 0; }

  17. 1st experiment—read and save a word #define LEN 20 int main(void){ char WordsString[LEN]; fprintf(stdout,"please input the first words:\n"); fscanf(stdin, "%s", WordsString); #ifdef p2_DEBUG fprintf(stdout,"First words is %s,\n", WordsString); for(i=0;i<LEN;i++) {fprintf(stdout,"The %d character of the first words is %c \n",i+1,WordsString[i]);} #endif return 0;}

  18. output please input the first words: note First words is note, The 1 character of the first words is n, The 2 character of the first words is o, The 3 character of the first words is t, The 4 character of the first words is e, The 5 character of the first words is , The 6 character of the first words is , The 7 character of the first words is �, The 8 character of the first words is �, The 9 character of the first words is �, The 10 character of the first words is D,

  19. 2nd experiment—read and save a word FIGURE 9.15 Char scanline(char *dest, int dest_len){ int i, ch; i=0; for (ch=getchar(); ch!='\n' && ch!=EOF && i<dest_len-1; ch=getchar()) dest[i++]=ch; dest[i]='\0'; while (ch!='\n'&&ch!=EOF) ch=getchar();

  20. 2nd experiment—modify FIGURE 9.15 Char scanline(char *dest, int dest_len){ int i, ch; i=0; for (ch=getchar();ch!='\n' && ch!=EOF && i<dest_len-1;ch=getchar()) dest[i++]=ch; //here, to add counter. dest[i]='\0'; while (ch!='\n'&&ch!=EOF) ch=getchar();

  21. Demonstration and Questions • Thanks! • If you have further questions, please post them to the Facebook group

More Related