{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

lecture16-feb27

# lecture16-feb27 - Announcements Lecture 16 Assignment 3 due...

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

Announcements Lecture 16 Assignment 3 due today Assignment 4 out on Monday Read rest of Ch. 22 for next week Topics for today – Finish Strings – Introduction to pointers (Ch. 11) • A very difficult subject for many String Reverser /* create a copy of a string in reverse order */ int i =0; char ch; char phrase [80] ; /* the initial string*/ char reversed [80] ; /* the reversed string*/ gets (phrase); i = strlen (phrase) -1; reversed = “”; while (i >= 0) { ch = phrase [i]; strcat (reversed, ch); i = i - 1; } reversed [strlen (phrase)] = ‘\0’; printf (“the reversed string is %s\n”, reversed); How would you turn this into a utility function? String Reverser - function void StringReverser (const char phrase [ ] , char reversed [ ] ) { /* precondition: assume that phrase has a legal string value */ /* postcondition: reversed will hold the reverse of phrase */ int i =0; char ch; i = strlen (phrase) - 1; reversed = “”; while (i >= 0) { ch = phrase [i]; strcat (reversed, ch); i = i - 1; } reversed [strlen (phrase)] = ‘\0’; return; } /* and then call it */ char str1[10], str2[10]; str1 = “desrever”; str2 = “”; StringReverser(str1,str2); . . . Array of strings Store the planets of our solar system as a 2D array of chars, with strings as the rows char planets [9] [8] = {“Mercury”, “Venus”, “Earth”, “Mars”, “Jupiter”, “Saturn”, “Uranus”, “Neptune”, “Pluto”}; char tempPlanet [8]; strcpy (tempPlanet, planets [2] [ ]); /* yields ?? */ Could you sort the planets into alphabetic order ?

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 / 3

lecture16-feb27 - Announcements Lecture 16 Assignment 3 due...

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

View Full Document
Ask a homework question - tutors are online