lect05 - CMSC 216 Introduction to Computer Systems Lecture...

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

View Full Document Right Arrow Icon
9/15/11 1 CMSC 216 Introduction to Computer Systems Lecture 5 Introduction to C Jan Plane & Pete Keleher {jplane, keleher}@cs.umd.edu Administrivia • Project 1 questions? • Project 1 Grading – If it gives the right answer but uses anything that is not in the list, the points are assigned as if you did not pass that test. • Lab exercise grading criteria CMSC 216 - Wood, 2
Background image of page 1

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

View Full Document Right Arrow Icon
9/15/11 2 Last Time: String library functions, cont. • Copying strings: strcpy(char dest[], char src[]); – copies the string in src to dest – it is up to the programmer to ensure that dest is an array with enough characters to hold the string • being lazy with this function can result in buffer overflows – Example: char str[] = "cherry"; char str2[10] = "milkshake"; strcpy(str2, str); 3 c h e r r y str2 \0 k e \0 A possible strcpy() implementation void strcpy(char dst[], char src[]) { int i = 0; while (src[i]) { dst[i] = src[i]; i++; } dst[i] = '\0'; } • What expression gives the minimum size of the array dst (to ensure safe execution)? 4
Background image of page 2
9/15/11 3 STRUCTURES AND UNIONS Chapter 10, Reek 5 Structures • Like arrays, hold multiple items • Items need not be of the same type • Items referred to by field names, not numerical indices • You can assign the value of another structure to a structure • You cannot use == or != • Similar to a Java class with all public fields and no methods 6
Background image of page 3

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

View Full Document Right Arrow Icon
9/15/11 4 Creating structures • Example: struct employee { int id_number; char last_name[10]; char first_name[10]; double salary; } emp1, emp2; • Declares two variables ( emp1 and emp2 ) of type struct employee employee is called the tag of these two structs
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.

{[ snackBarMessage ]}

Page1 / 12

lect05 - CMSC 216 Introduction to Computer Systems Lecture...

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