Lecture21

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

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

View Full Document
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'};
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)

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

View Full Document
Passing arrays as parameters void f(double *x, int size); ... const int n = 12; double a[n]; ... f(a,n)
• 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'};

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.

This note was uploaded on 01/21/2012 for the course ECON 2a taught by Professor Xi during the Spring '11 term at Cornell College.

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