Professional Documents
Culture Documents
08outlineW3W PDF
08outlineW3W PDF
Last Time
Return Values and Pointers
Parameter and Return Value Caveats
Structures
Nested structs and Arrays of structs
Today
Pointers to structs (from last time)
Strings and string.h.
Standard & String I/O and stdio.h
File I/O and stdio.h
Next Time
Read: B&O 9.9.1 - 9.9.2
C Abstract Memory Model
Address Space Layout
Dynamic Memory Intro
CS 354 (F16): L7 - 1
Strings
What?
How?
If each of the following code fragments is in a main function with necessary #includes
what happens when the code is attempted to be compiled and run?
1.
2.
3.
4.
CS 354 (F16): L7 - 2
string.h Library
What?
Returns the length of string str up to but not including the null character.
CS 354 (F16): L7 - 3
String I/O
int sprintf(char *str, const char *format, ...)
CS 354 (F16): L7 - 4
File I/O
File Output
fputc/putc, fputs
int fprintf(FILE *stream, const char *format, ...)
File Input
fgetc/getc, ungetc, fgets
int fscanf(FILE *stream, const char *format, ...)
File Pointers
Opening/Closing
FILE *fopen(const char *filename, const char *mode)
CS 354 (F16): L7 - 5
#include <stdio.h>
#include <stdlib.h>
return 0;
}
CS 354 (F16): L7 - 6