March R. 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
March R. 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
March R. 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
March R. 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
March R. 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?
March R. 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?
March R. 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
March R. 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
March R. 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
March R. 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 sa/3.0/us/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.