exam3_f09

exam3_f09 - Exam 3 ECS 102 Dr. Baruch Fall 2009 Name:...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
Exam 3 ECS 102 Dr. Baruch Fall 2009 Name: problem points score 1 13 2 16 3 10 4 10 5 10 6 14 7 17 8 10 Total 100 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
1. Write a function void subString( char early[ ], char later[ ], int startIndex, int endIndex) that copies the piece of early from position startIndex to position endIndex to the variable later . It should then null terminate later to make it a string. If endIndex is beyond the string length of early (as determined by the \ 0), the function should copy only up to the null character of early . If startIndex is below 0, copying should start at 0. If startIndex is greater than endIndex , no copying should happen. Example: Before function call: early: [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] p i n e a p p l e \ 0 x x x later: [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] g r a p e f r u i t \ 0 x x after the call: subSting( early, later, 4, 8) early: [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] p i n e a p p l e \ 0 x x x later: [0] [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] a p p l e \ 0 r u i t \ 0 x x 2
Background image of page 2
2. For each of the following, what will be the output ? (a) char s[] = "dog"; char t[] = "deer"; if (strcmp(s,t) < 0) printf("wild\n"); else printf("tame\n"); (b) char x[] = "big"; char y[] = "far"; x[0]=y[0]; printf("%s %s\n",x, y); (c) char a[] = "north"; char b[] = "south"; strcpy(a,b); printf("%s\n",a); printf("%s\n",b); (d) char tall[] = "HEAVY"; char short[] = "heavy"; if (strcmp(tall,short) == 0) printf("same\n"); else printf("different\n"); (e) char op[] = "add"; printf("%d\n", strlen(op)); (f) char z[] = "table"; z[3]=’\0’; printf("%s\n",z); 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
3. Given the function int compute(int n) { int ans;
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 10

exam3_f09 - Exam 3 ECS 102 Dr. Baruch Fall 2009 Name:...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online