Presentation is loading. Please wait.

Presentation is loading. Please wait.

March 2005 1R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Upcoming Exam – April 8Upcoming Exam – April 8 Structures ReviewStructures.

Similar presentations


Presentation on theme: "March 2005 1R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Upcoming Exam – April 8Upcoming Exam – April 8 Structures ReviewStructures."— Presentation transcript:

1 March 2005 1R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Upcoming Exam – April 8Upcoming Exam – April 8 Structures ReviewStructures Review StringsStrings Lab 14 – brief introLab 14 – brief intro

2 March 2005 2R. Smith - University of St Thomas - Minnesota Structures Review FOUR Steps, not three stepsFOUR Steps, not three steps –1) Define the struct’s format (what variables are inside) –2) Declare the struct variable –3) Initialize the struct variable –4) Use the struct variable You can define, declare, and initialize all at once, or do them separatelyYou can define, declare, and initialize all at once, or do them separately Where do the struct definitions go?Where do the struct definitions go? –“Outside” the functions that use them

3 March 2005 3R. Smith - University of St Thomas - Minnesota Defining, Declaring, Using Struct definitionStruct definition Struct declarationStruct declaration Referencing fields inside the structReferencing fields inside the struct Arrays of structsArrays of structs Arrays in structsArrays in structs

4 March 2005 4R. Smith - University of St Thomas - Minnesota Strings! Character arrays that end with a ‘null’Character arrays that end with a ‘null’ –NOT a zero (“0”), which has a numeric value of 48, –but rather an actual numeric value of zero (not a character) When we say char x[] = “abc”;When we say char x[] = “abc”; –we get FOUR characters, the last being null Reading %s with scanfReading %s with scanf –Strings are ARRAYS -> we don’t need & in front –Example: reading in and printing two strings

5 March 2005 5R. Smith - University of St Thomas - Minnesota Example: concatenating two strings How do we do it?How do we do it? The problem:The problem: –Take two strings –Copy them to a third array, one after the other. How do we detect the end of a string?How do we detect the end of a string?

6 March 2005 6R. Smith - University of St Thomas - Minnesota Example: Comparing 2 strings Do we just say str1 == str2?Do we just say str1 == str2? What are we comparing then?What are we comparing then? How do we actually compare the characters?How do we actually compare the characters?

7 March 2005 7R. Smith - University of St Thomas - Minnesota Reading “Raw” Characters The getchar() functionThe getchar() function How do we write a function to read a line of text?How do we write a function to read a line of text? How does a line end, when typed in?How does a line end, when typed in? CR vs LFCR vs LF

8 March 2005 8R. Smith - University of St Thomas - Minnesota Characters and Numbers Printing out the character codesPrinting out the character codes Digits to numbersDigits to numbers Upper versus lower caseUpper versus lower case

9 March 2005 9R. Smith - University of St Thomas - Minnesota Lab 14 Convert a typed line of text to Pig LatinConvert a typed line of text to Pig Latin –Words that start with consonants Strip the leading consonantsStrip the leading consonants Append to end of the wordAppend to end of the word Add “ay”Add “ay” –Words that start with vowels Append “way” to end of the wordAppend “way” to end of the word –Keep running until a “blank” line is typed FunctionsFunctions –Read a line of text –Test for vowel –Index of next vowel –Index of next blank

10 March 2005 10R. Smith - University of St Thomas - Minnesota Creative Commons License This work is licensed under the Creative Commons Attribution-Share Alike 3.0 United States License. To view a copy of this license, visit http://creativecommons.org/licenses/by- sa/3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.


Download ppt "March 2005 1R. Smith - University of St Thomas - Minnesota QMCS 130: Today’s Class Upcoming Exam – April 8Upcoming Exam – April 8 Structures ReviewStructures."

Similar presentations


Ads by Google