Lecture25 - ECS 30 Introduction to Programming and Problem...

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

View Full Document Right Arrow Icon
ECS 30 Introduction to Programming and Problem Solving François Gygi Department of Computer Science
Background image of page 1

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

View Full DocumentRight Arrow Icon
Lecture 25 • Data structures – linked list • Teaching evaluations • Friday Dec 2: review session – prepare questions
Background image of page 2
Storing a set of items • Consider a set of personal data records defined as struct data_t { char firstname[64]; char lastname[64]; int age; };
Background image of page 3

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

View Full DocumentRight Arrow Icon
Storing a set of items • Consider a set of personal data records defined as struct data_t { char firstname[64]; char lastname[64]; int age; }; typedef struct data_t person_t;
Background image of page 4
Solution 1 • Use an array of person_t person_t guests[20]; ... /* use the array */ guests[3].age = 25; ... program guests.c
Background image of page 5

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

View Full DocumentRight Arrow Icon
Solution 1 • Use an array of person_t person_t guests[10]; ... /* use the array */ guests[3].age = 25; • Problem: the maximum size (10) must be known in advance
Background image of page 6
Solution 2 • Use dynamic memory allocation – first read the size from the file – allocate an array of person_t using malloc – read the data into the array elements
Background image of page 7

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

View Full DocumentRight Arrow Icon
Image of page 8
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 19

Lecture25 - ECS 30 Introduction to Programming and Problem...

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

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