Lecture21 - 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 21 • Using character strings
Background image of page 2
Strings are arrays of characters • Representation of the string “data.txt”: char name[8]= {'d','a','t','a','.','t','x','t'};
Background image of page 3

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

View Full DocumentRight Arrow Icon
Strings are arrays of characters • Implicit size declaration – no need to count the elements of the array int x[]= { 2, 7, 4, 3, 8 }; • Representation of the string “data.txt”: char name[]= {'d','a','t','a','.','t','x','t'};
Background image of page 4
Passing arrays as parameters • When passing arrays as parameters to functions, we must specify – pointer to first element of the array – size of the array • Example: pass an array of double as a parameter to the function f void f(double *x, int size); ... f(a,n)
Background image of page 5

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

View Full DocumentRight Arrow Icon
Passing arrays as parameters void f(double *x, int size); ... const int n = 12; double a[n]; ... f(a,n)
Background image of page 6
• When using character strings, one would have to keep track of string sizes: this is inconvenient • Terminating null character: '\0' – Indicates the end of a string • Include a null character when initializing a string: char name[] = {'d','a','t','a','\0'};
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 / 23

Lecture21 - 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