Lecture25

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

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

ECS 30 Introduction to Programming and Problem Solving François Gygi Department of Computer Science

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

View Full Document
Lecture 25 • Data structures – linked list • Teaching evaluations • Friday Dec 2: review session – prepare questions
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; };

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

View Full Document
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;
Solution 1 • Use an array of person_t person_t guests[20]; ... /* use the array */ guests[3].age = 25; ... program guests.c

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

View Full Document
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
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

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online