Unit 10 Miscellaneous Advanced Topics Introduction to C Programming.
-
Upload
jonathan-hill -
Category
Documents
-
view
216 -
download
1
Transcript of Unit 10 Miscellaneous Advanced Topics Introduction to C Programming.
Unit 10
MiscellaneousAdvanced Topics
Introduction toC Programming
Unit 9 Review
Unit 10: Review of Past Material
Unit 9 Review - StringsStrings are manipulated with the string library
The string library is made available by including <string.h>
The strcpy() function copies from one string to anotherConcatenation (joining) of two strings uses the strcat()
functionThe strlen() function returns the string lengthVersions of the string functions that contain the letter 'n'
strncat()strncpy()strncmp()
The sscanf() and sprintf() functions read and write strings
Unit 9 Review - FilesYou must first use a FILE * (file pointer) variableUse fopen() to access a file, and fclose() when
doneUsing the "r" mode allows a file to be opened for
readingUsing the "w" mode empties/creates a file for
writingUse fscanf() and fprintf() to read and write text
filesUse fread() and fwrite() to read and write binary
files
Recursive Functions
Unit 10: Miscellaneous Advanced Topics
Recursive FunctionsA problem which is defined in terms of a
simpler version is suitable for a recursive solution
For example, 2^n = 2 * 2^(n-1)A recursive function calls itself for a simpler
version of the problemThe base problem (n=0 or n=1) must be a
known answerFor example, 2^1 = 2
Structures
Unit 10: Miscellaneous Advanced Topics
StructuresA structure is an implementation of a database
recordA record is a collection of related information stored
in fieldsExample: First-name, Last-name, Telephone-numberC language syntax
Keyword "struct" followed by braceDeclare each field just like a variable declarationClosing brace
Fields can be arrays or other structuresData is placed consecutively in memory, making a
block
Unions
Unit 10: Miscellaneous Advanced Topics
UnionsSyntax is like a struct, except for keyword unionThe fields are mutually exclusive, only one
applies at any timeThe memory for each field is overlaid in the
same physical memory, all starting at the same location (beginning of union)
Typically, a union appears as part of a larger struct record
There is typically a sentinel variable which is used in the program to determine which is the applicable union member to use